Skip to content

Commit

Permalink
Merge 3c59688 into d20e32e
Browse files Browse the repository at this point in the history
  • Loading branch information
jesuslosada committed Oct 27, 2018
2 parents d20e32e + 3c59688 commit 52cca28
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 29 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ language: python

matrix:
include:
- python: 3.7
dist: xenial
sudo: true
env: TOX_ENV=py37
- python: 3.6
env: TOX_ENV=py36
- python: 2.7
Expand Down
7 changes: 6 additions & 1 deletion schematics/datastructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
# pylint: skip-file

from __future__ import unicode_literals, absolute_import
from collections import Mapping, Sequence

from .compat import *

try:
from collections.abc import Mapping, Sequence # PY3
except ImportError:
from collections import Mapping, Sequence # PY2


__all__ = []


Expand Down
10 changes: 7 additions & 3 deletions schematics/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

import json

from collections import Sequence, Mapping

from .translator import LazyText
from .common import *
from .compat import string_type, str_compat
from .datastructures import FrozenDict, FrozenList
from .translator import LazyText

try:
from collections.abc import Mapping, Sequence # PY3
except ImportError:
from collections import Mapping, Sequence # PY2


__all__ = [
'BaseError', 'ErrorMessage', 'FieldError', 'ConversionError',
Expand Down
9 changes: 6 additions & 3 deletions schematics/role.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import collections

from .compat import str_compat, repr_compat

try:
from collections.abc import Set # PY3
except ImportError:
from collections import Set # PY2


@repr_compat
@str_compat
class Role(collections.Set):
class Role(Set):

"""
A ``Role`` object can be used to filter specific fields against a sequence.
Expand Down
17 changes: 12 additions & 5 deletions schematics/types/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

from __future__ import unicode_literals, absolute_import

try:
import typing
except ImportError:
pass

import copy
import datetime
Expand All @@ -16,7 +12,7 @@
import re
import string
import uuid
from collections import Iterable, OrderedDict
from collections import OrderedDict

from ..common import *
from ..exceptions import *
Expand All @@ -25,6 +21,17 @@
from ..util import listify
from ..validate import prepare_validator, get_validation_context

try:
import typing
except ImportError:
pass

try:
from collections.abc import Iterable # PY3
except ImportError:
from collections import Iterable # PY2


__all__ = [
'BaseType', 'UUIDType', 'StringType', 'MultilingualStringType',
'NumberType', 'IntType', 'LongType', 'FloatType', 'DecimalType',
Expand Down
21 changes: 12 additions & 9 deletions schematics/types/compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@

from __future__ import unicode_literals, absolute_import

try:
import typing
except ImportError:
pass
else:
T = typing.TypeVar("T")

from collections import Iterable, Sequence, Mapping
import itertools

from ..common import *
Expand All @@ -20,9 +12,20 @@
to_native_converter, to_primitive_converter)
from ..translator import _
from ..util import get_all_subclasses, import_string

from .base import BaseType, get_value_in

try:
import typing
except ImportError:
pass
else:
T = typing.TypeVar("T")

try:
from collections.abc import Iterable, Sequence, Mapping # PY3
except ImportError:
from collections import Iterable, Sequence, Mapping # PY2

__all__ = ['CompoundType', 'MultiType', 'ModelType', 'ListType', 'DictType',
'PolyModelType']

Expand Down
6 changes: 5 additions & 1 deletion schematics/types/union.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
def _valid_init_args(type_):
args = set()
for cls in type_.__mro__:
args.update(inspect.getargspec(cls.__init__).args[1:])
try:
init_args = inspect.getfullargspec(cls.__init__).args[1:] # PY3
except AttributeError:
init_args = inspect.getargspec(cls.__init__).args[1:] # PY2
args.update(init_args)
if cls is BaseType:
break
return args
Expand Down
8 changes: 6 additions & 2 deletions schematics/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

from __future__ import unicode_literals, absolute_import

import collections
import sys

from .compat import *

try:
from collections.abc import Sequence # PY3
except ImportError:
from collections import Sequence # PY2

if PY2:
try:
from thread import get_ident
Expand Down Expand Up @@ -59,7 +63,7 @@ def listify(value):
return []
elif isinstance(value, string_type):
return [value]
elif isinstance(value, collections.Sequence):
elif isinstance(value, Sequence):
return list(value)
else:
return [value]
Expand Down
6 changes: 5 additions & 1 deletion schematics/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ def get_validation_context(**options):
def prepare_validator(func, argcount):
if isinstance(func, classmethod):
func = func.__get__(object).__func__
if len(inspect.getargspec(func).args) < argcount:
try:
func_args = inspect.getfullargspec(func).args # PY3
except AttributeError:
func_args = inspect.getargspec(func).args # PY2
if len(func_args) < argcount:
@functools.wraps(func)
def newfunc(*args, **kwargs):
if not kwargs or kwargs.pop('context', 0) is 0:
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
],
install_requires=[],
)
6 changes: 3 additions & 3 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,10 @@ def test_string_min_length_doesnt_accept_empty_string():


def test_string_regex():
StringType(regex='\d+').validate("1")
StringType(regex=r'\d+').validate("1")

with pytest.raises(ValidationError):
StringType(regex='\d+').validate("a")
StringType(regex=r'\d+').validate("a")


def test_string_to_native():
Expand Down Expand Up @@ -461,7 +461,7 @@ def test_multilingualstring_should_validate_regex():
MultilingualStringType(regex='^[a-z]*$').validate({'en_US': '123'})

with pytest.raises(ValidationError):
MultilingualStringType(locale_regex='^\d*$').validate({'en_US': 'foo'})
MultilingualStringType(locale_regex=r'^\d*$').validate({'en_US': 'foo'})

assert MultilingualStringType(locale_regex=None).validate_regex({'en_US': 'foo'}) is None

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py27, py33, py34, py35, py36, pypy, pypy3
envlist = py27, py33, py34, py35, py36, py37, pypy, pypy3

[testenv]
deps = -r{toxinidir}/test-requirements.txt
Expand Down

0 comments on commit 52cca28

Please sign in to comment.