From d657d56211c56cce1e6f583b3ecdb0b781ef4f6c Mon Sep 17 00:00:00 2001 From: Maxim Avanov Date: Sun, 1 Jul 2018 23:09:04 +0100 Subject: [PATCH 1/2] Fix Sequence issue on Python 3.7 --- tests/test_parser.py | 4 +++- typeit/parser.py | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/test_parser.py b/tests/test_parser.py index 21c7b7b..52b8f64 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -26,11 +26,13 @@ def test_type_with_sequence(): class X(NamedTuple): x: int y: Sequence[Any] + z: Sequence[str] MkX = p.type_constructor(X) - x: X = MkX({'x': 1, 'y': []}) + x: X = MkX({'x': 1, 'y': [], 'z': ['Hello']}) assert x.y == [] + assert x.z[0] == 'Hello' def test_type_with_empty_enum_variant(): diff --git a/typeit/parser.py b/typeit/parser.py index a4ea18b..e43bcd3 100644 --- a/typeit/parser.py +++ b/typeit/parser.py @@ -5,6 +5,7 @@ Dict, NamedTuple, Callable, Sequence, get_type_hints ) +import collections import inflection import colander as col @@ -183,6 +184,7 @@ def _maybe_node_for_builtin(typ) -> Optional[col.SchemaNode]: def _maybe_node_for_enum(typ) -> Optional[col.SchemaNode]: + print(typ, type(typ), insp.get_origin(typ), insp.get_origin(typ) is Sequence) if issubclass(typ, std_enum.Enum): return col.SchemaNode(schema.Enum(typ, allow_empty=True)) return None @@ -221,7 +223,10 @@ def _maybe_node_for_list(typ) -> Optional[col.SequenceSchema]: # typ is List[T] where T is either unknown Any or a concrete type if typ in (List[Any], Sequence[Any]): return col.SequenceSchema(col.SchemaNode(col.Str(allow_empty=True))) - elif insp.get_origin(typ) in (List, Sequence, list): + elif insp.get_origin(typ) in (List, + Sequence, + collections.abc.Sequence, + list): inner = insp.get_args(typ)[0] return col.SequenceSchema(decide_node_type(inner)) return None From 38b2dc9a1f1324d0b7052642771cea2e9a9248d9 Mon Sep 17 00:00:00 2001 From: Maxim Avanov Date: Sun, 1 Jul 2018 23:09:48 +0100 Subject: [PATCH 2/2] Hotfix release 0.5.1 --- docs/conf.py | 2 +- setup.py | 2 +- typeit/parser.py | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 0cb6c7c..a45b907 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -53,7 +53,7 @@ # The short X.Y version. version = '0.5' # The full version, including alpha/beta/rc tags. -release = '0.5.0' +release = '0.5.1' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/setup.py b/setup.py index 8e78225..b12a4ef 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ # ---------------------------- setup(name='typeit', - version='0.5.0', + version='0.5.1', description='Type it!', long_description=README, classifiers=[ diff --git a/typeit/parser.py b/typeit/parser.py index e43bcd3..08fdf83 100644 --- a/typeit/parser.py +++ b/typeit/parser.py @@ -184,7 +184,6 @@ def _maybe_node_for_builtin(typ) -> Optional[col.SchemaNode]: def _maybe_node_for_enum(typ) -> Optional[col.SchemaNode]: - print(typ, type(typ), insp.get_origin(typ), insp.get_origin(typ) is Sequence) if issubclass(typ, std_enum.Enum): return col.SchemaNode(schema.Enum(typ, allow_empty=True)) return None