Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility imports of abstract base classes #451

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ python:
- 3.4
- 3.5
- 3.6
- 3.7-dev # FIXME when 3.7 is available
- pypy
- pypy3
install: travis_retry pip install tox-travis
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM funkyfuture/nest-of-serpents
ENTRYPOINT tox
WORKDIR /src

RUN pip3.6 install black flake8 pre-commit pytest tox PyYAML Sphinx \
RUN pip3.7 install black flake8 pre-commit pytest tox PyYAML Sphinx \
&& mkdir /home/tox \
&& mv /root/.cache /home/tox/

Expand Down
26 changes: 26 additions & 0 deletions cerberus/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
2 changes: 1 addition & 1 deletion cerberus/schema.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -12,6 +11,7 @@
mapping_hash,
TypeDefinition,
)
from cerberus.platform import Callable, Hashable, Mapping, MutableMapping, Sequence


class _Abort(Exception):
Expand Down
4 changes: 2 additions & 2 deletions cerberus/utils.py
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
13 changes: 10 additions & 3 deletions cerberus/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -27,7 +35,6 @@
)
from cerberus.utils import drop_item_from_tuple, readonly_classproperty, TypeDefinition


toy_error_handler = errors.ToyErrorHandler()


Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
],
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist=py27,py34,py35,py36,pypy,pypy3,doclinks,doctest,linting
envlist=py27,py34,py35,py36,py37,pypy,pypy3,doclinks,doctest,linting

[testenv]
deps=pytest
Expand All @@ -20,7 +20,6 @@ commands=make doctest

[testenv:linting]
skipsdist=True
basepython=python3.6
deps=pre-commit
commands=pre-commit run --config .linting-config.yaml --all-files

Expand All @@ -32,6 +31,7 @@ ignore=E203,W503
2.7 = py27
3.4 = py34
3.5 = py35
3.6 = py36,doclinks,doctest,linting
3.6 = py36
3.7 = py37,doclinks,doctest,linting
pypy = pypy
pypy3 = pypy3