diff --git a/.travis.yml b/.travis.yml index 0d468c4..3363e0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,17 @@ # Config file for automatic testing at travis-ci.org language: python -python: - - "3.4" - - "3.3" - - "2.7" - - "pypy" +dist: xenial + +matrix: + include: + - python: "3.8" + - python: "3.4" + - python: "3.3" + dist: trusty + - python: "2.7" + - python: "pypy" + install: pip install coveralls script: coverage run --source=valideer setup.py test after_success: coveralls diff --git a/setup.py b/setup.py index ff38c0b..4731f07 100644 --- a/setup.py +++ b/setup.py @@ -24,6 +24,7 @@ "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.8", "Topic :: Software Development :: Libraries :: Python Modules", "License :: OSI Approved :: MIT License", ], diff --git a/valideer/compat.py b/valideer/compat.py index d98b19a..3d4b49d 100644 --- a/valideer/compat.py +++ b/valideer/compat.py @@ -21,6 +21,12 @@ iteritems = dict.items xrange = range +# Fix Python > 3.7 deprecation and preserve Python 3.3 compatibility +try: + import collections.abc as collections_abc +except ImportError: + import collections as collections_abc + def with_metaclass(mcls): def decorator(cls): diff --git a/valideer/tests/test_validators.py b/valideer/tests/test_validators.py index 66b3eb0..43f57fa 100644 --- a/valideer/tests/test_validators.py +++ b/valideer/tests/test_validators.py @@ -6,7 +6,7 @@ import re import unittest import valideer as V -from valideer.compat import long, unicode, xrange, string_types, int_types +from valideer.compat import long, unicode, xrange, string_types, int_types, collections_abc class Fraction(V.Type): @@ -942,8 +942,8 @@ def test_error_message_json_type_names(self): V.set_name_for_types("integer", int, long) V.set_name_for_types("number", float) V.set_name_for_types("string", str, unicode) - V.set_name_for_types("array", list, collections.Sequence) - V.set_name_for_types("object", dict, collections.Mapping) + V.set_name_for_types("array", list, collections_abc.Sequence) + V.set_name_for_types("object", dict, collections_abc.Mapping) self._testValidation({"+foo": "number", "?bar": ["integer"], diff --git a/valideer/validators.py b/valideer/validators.py index ebd91f3..9f192b0 100644 --- a/valideer/validators.py +++ b/valideer/validators.py @@ -1,6 +1,5 @@ from .base import Validator, ValidationError, parse, get_type_name -from .compat import string_types, izip, imap, iteritems -import collections +from .compat import string_types, izip, imap, iteritems, collections_abc import datetime import inspect import numbers @@ -466,7 +465,7 @@ def _PatternFactory(obj): class HomogeneousSequence(Type): """A validator that accepts homogeneous, non-fixed size sequences.""" - accept_types = collections.Sequence + accept_types = collections_abc.Sequence reject_types = string_types def __init__(self, item_schema=None, min_length=None, max_length=None): @@ -519,7 +518,7 @@ def _HomogeneousSequenceFactory(obj): class HeterogeneousSequence(Type): """A validator that accepts heterogeneous, fixed size sequences.""" - accept_types = collections.Sequence + accept_types = collections_abc.Sequence reject_types = string_types def __init__(self, *item_schemas): @@ -561,7 +560,7 @@ def _HeterogeneousSequenceFactory(obj): class Mapping(Type): """A validator that accepts mappings (:py:class:`collections.Mapping` instances).""" - accept_types = collections.Mapping + accept_types = collections_abc.Mapping def __init__(self, key_schema=None, value_schema=None): """Instantiate a :py:class:`Mapping` validator. @@ -610,7 +609,7 @@ class Object(Type): "properties", i.e. string keys. """ - accept_types = collections.Mapping + accept_types = collections_abc.Mapping REQUIRED_PROPERTIES = False ADDITIONAL_PROPERTIES = True