From da16545e6fbb46b1d57822fb720fa91ef4a46366 Mon Sep 17 00:00:00 2001 From: Frank Sachsenheim Date: Wed, 3 Oct 2018 21:38:11 +0200 Subject: [PATCH] Imports abstract base classes from the platform module Closes #450 --- cerberus/platform.py | 26 ++++++++++++++++++++++++++ cerberus/schema.py | 2 +- cerberus/utils.py | 4 ++-- cerberus/validator.py | 13 ++++++++++--- 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/cerberus/platform.py b/cerberus/platform.py index eca9858d..66b1d5f0 100644 --- a/cerberus/platform.py +++ b/cerberus/platform.py @@ -12,3 +12,29 @@ else: _str_type = str _int_types = (int,) + + +if PYTHON_VERSION < 3.3: + from collections import ( # noqa: F401 + Callable, + Container, + Hashable, + Iterable, + Mapping, + MutableMapping, + Sequence, + Set, + Sized, + ) +else: + from collections.abc import ( # noqa: F401 + Callable, + Container, + Hashable, + Iterable, + Mapping, + MutableMapping, + Sequence, + Set, + Sized, + ) diff --git a/cerberus/schema.py b/cerberus/schema.py index 6c865d87..4b18639c 100644 --- a/cerberus/schema.py +++ b/cerberus/schema.py @@ -1,6 +1,5 @@ from __future__ import absolute_import -from collections import Callable, Hashable, Mapping, MutableMapping, Sequence from copy import copy from warnings import warn @@ -12,6 +11,7 @@ mapping_hash, TypeDefinition, ) +from cerberus.platform import Callable, Hashable, Mapping, MutableMapping, Sequence class _Abort(Exception): diff --git a/cerberus/utils.py b/cerberus/utils.py index c0d157ad..a12ebfc5 100644 --- a/cerberus/utils.py +++ b/cerberus/utils.py @@ -1,8 +1,8 @@ from __future__ import absolute_import -from collections import Mapping, namedtuple, Sequence, Set +from collections import namedtuple -from cerberus.platform import _int_types, _str_type +from cerberus.platform import _int_types, _str_type, Mapping, Sequence, Set TypeDefinition = namedtuple('TypeDefinition', 'name,included_types,excluded_types') diff --git a/cerberus/validator.py b/cerberus/validator.py index 17981e31..61bffa79 100644 --- a/cerberus/validator.py +++ b/cerberus/validator.py @@ -11,14 +11,22 @@ from __future__ import absolute_import from ast import literal_eval -from collections import Container, Hashable, Iterable, Mapping, Sequence, Sized from copy import copy from datetime import date, datetime import re from warnings import warn from cerberus import errors -from cerberus.platform import _int_types, _str_type +from cerberus.platform import ( + _int_types, + _str_type, + Container, + Hashable, + Iterable, + Mapping, + Sequence, + Sized, +) from cerberus.schema import ( schema_registry, rules_set_registry, @@ -27,7 +35,6 @@ ) from cerberus.utils import drop_item_from_tuple, readonly_classproperty, TypeDefinition - toy_error_handler = errors.ToyErrorHandler()