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

Add Python 3.9 support #25

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 11 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
6 changes: 6 additions & 0 deletions valideer/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions valideer/tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"],
Expand Down
11 changes: 5 additions & 6 deletions valideer/validators.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down