From 4f46619b851df9f266b79ed5894c97287a39fcf4 Mon Sep 17 00:00:00 2001 From: Alex Sopov Date: Sun, 8 Mar 2020 20:34:50 +0200 Subject: [PATCH 1/4] Import ABCs from 'collections.abc' rather than 'collections'. On Python < 3.3 fall back to 'collections'. --- valideer/compat.py | 6 ++++++ valideer/tests/test_validators.py | 6 +++--- valideer/validators.py | 11 +++++------ 3 files changed, 14 insertions(+), 9 deletions(-) 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 From 149941a4d58c1b34b35ce311bf02f2402a01ed18 Mon Sep 17 00:00:00 2001 From: Alex Sopov Date: Sun, 8 Mar 2020 22:50:44 +0200 Subject: [PATCH 2/4] Add CI build on Python 3.8 --- .travis.yml | 1 + setup.py | 1 + 2 files changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 0d468c4..7ce0ce8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: python python: + - "3.8" - "3.4" - "3.3" - "2.7" 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", ], From 18c70abefb54794e007b8672d2aed14c0e70febb Mon Sep 17 00:00:00 2001 From: Alex Sopov Date: Sun, 8 Mar 2020 23:41:22 +0200 Subject: [PATCH 3/4] Update .travis.yml. Add fixed version of distribution and build using Python 3.3 on trusty --- .travis.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7ce0ce8..d54ab55 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,18 @@ # Config file for automatic testing at travis-ci.org language: python -python: - - "3.8" - - "3.4" - - "3.3" - - "2.7" - - "pypy" +dist: xenial + +matrix: + include: + - python: + - "3.8" + - "3.4" + - "2.7" + - "pypy" + - python: "3.3" + dist: trusty + install: pip install coveralls script: coverage run --source=valideer setup.py test after_success: coveralls From 9e88202baf37f31cbb2ec751d02d1c97fccd5005 Mon Sep 17 00:00:00 2001 From: Alex Sopov Date: Sun, 8 Mar 2020 23:44:55 +0200 Subject: [PATCH 4/4] Fix CI matrix. Use each Python version as separate step --- .travis.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index d54ab55..3363e0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,13 +5,12 @@ dist: xenial matrix: include: - - python: - - "3.8" - - "3.4" - - "2.7" - - "pypy" + - 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