From 0d4e81bcc5a8954af8c7263042c04dd7ac0fb9e0 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Mon, 19 Mar 2018 22:32:48 +0000 Subject: [PATCH 01/13] Support Python 3.7 --- typing_inspect.py | 61 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/typing_inspect.py b/typing_inspect.py index f39f311..64ea5e3 100644 --- a/typing_inspect.py +++ b/typing_inspect.py @@ -7,10 +7,19 @@ # NOTE: This module must support Python 2.7 in addition to Python 3.x -from typing import ( - Callable, CallableMeta, Union, _Union, TupleMeta, TypeVar, - _ClassVar, GenericMeta, -) +import sys +import collections.abc + +NEW_TYPING = sys.version_info[:3] >= (3, 7, 0) # PEP 560 + + +if NEW_TYPING: + from typing import Callable, Union, TypeVar, ClassVar, Tuple, _GenericAlias +else: + from typing import ( + Callable, CallableMeta, Union, _Union, TupleMeta, TypeVar, + _ClassVar, GenericMeta, + ) def _gorg(cls): @@ -41,7 +50,8 @@ def is_generic_type(tp): is_generic_type(MutableMapping[T, List[int]]) == True is_generic_type(Sequence[Union[str, bytes]]) == True """ - + if NEW_TYPING: + return isinstance(tp, Generic) or isinstance(tp, _GenericAlias) return (isinstance(tp, GenericMeta) and not isinstance(tp, (CallableMeta, TupleMeta))) @@ -65,7 +75,8 @@ class MyClass(Callable[[int], int]): get_origin(tp) is Callable """ - + if NEW_TYPING: + return tp is Callable or isinstance(tp, _GenericAlias) and tp.__origin__ is collections.abc.Callable return type(tp) is CallableMeta @@ -87,7 +98,8 @@ class MyClass(Tuple[str, int]): get_origin(tp) is Tuple """ - + if NEW_TYPING: + return tp is Tuple or isinstance(tp, _GenericAlias) and tp.__origin__ is tuple return type(tp) is TupleMeta @@ -99,7 +111,8 @@ def is_union_type(tp): is_union_type(Union[int, int]) == False is_union_type(Union[T, int]) == True """ - + if NEW_TYPING: + return tp is Union or isinstance(tp, _GenericAlias) and tp.__origin__ is Union return type(tp) is _Union @@ -122,14 +135,15 @@ def is_classvar(tp): is_classvar(ClassVar[int]) == True is_classvar(ClassVar[List[T]]) == True """ - + if NEW_TYPING: + return tp is ClassVar or isinstance(tp, _GenericAlias) and tp.__origin__ is ClassVar return type(tp) is _ClassVar def get_last_origin(tp): """Get the last base of (multiply) subscripted type. Supports generic types, - Union, Callable, and Tuple. Returns None for unsupported types. - Examples:: + Union, Callable, and Tuple. Returns None for unsupported types. + Examples:: get_last_origin(int) == None get_last_origin(ClassVar[int]) == None @@ -137,8 +151,9 @@ def get_last_origin(tp): get_last_origin(Union[T, int][str]) == Union[T, int] get_last_origin(List[Tuple[T, T]][int]) == List[Tuple[T, T]] get_last_origin(List) == List - """ - + """ + if NEW_TYPING: + raise ValueError('This function is only supported in Python 3.6, use get_origin instead') sentinel = object() origin = getattr(tp, '__origin__', sentinel) if origin is sentinel: @@ -159,7 +174,12 @@ def get_origin(tp): get_origin(Union[T, int]) == Union get_origin(List[Tuple[T, T]][int]) == List """ - + if NEW_TYPING: + if isinstance(tp, _GenericAlias): + return tp.__origin__ + if tp is Generic: + return Generic + return None if isinstance(tp, GenericMeta): return _gorg(tp) if is_union_type(tp): @@ -183,7 +203,10 @@ def get_parameters(tp): get_parameters(Union[S_co, Tuple[T, T]][int, U]) == (U,) get_parameters(Mapping[T, Tuple[S_co, T]]) == (T, S_co) """ - + if NEW_TYPING: + if isinstance(tp, _GenericAlias) or issubclass(tp, Generic): + return tp.__parameters__ + return () if ( is_generic_type(tp) or is_union_type(tp) or is_callable_type(tp) or is_tuple_type(tp) @@ -204,7 +227,8 @@ def get_last_args(tp): get_last_args(Callable[[T], int]) == (T, int) get_last_args(Callable[[], int]) == (int,) """ - + if NEW_TYPING: + raise ValueError('This function is only supported in Python 3.6, use get_args instead') if is_classvar(tp): return (tp.__type__,) if tp.__type__ is not None else () if ( @@ -251,7 +275,10 @@ def get_args(tp, evaluate=False): (int, Tuple[Optional[int], Optional[int]]) get_args(Callable[[], T][int], evaluate=True) == ([], int,) """ - + if NEW_TYPING: + if isinstance(tp, _GenericAlias): + return tp.__args__ + return () if is_classvar(tp): return (tp.__type__,) if ( From cb19c4970dd7bd22fae608badae73469bf02f56d Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Mon, 19 Mar 2018 22:38:07 +0000 Subject: [PATCH 02/13] Fix imports --- typing_inspect.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/typing_inspect.py b/typing_inspect.py index 64ea5e3..8005d88 100644 --- a/typing_inspect.py +++ b/typing_inspect.py @@ -8,13 +8,13 @@ # NOTE: This module must support Python 2.7 in addition to Python 3.x import sys -import collections.abc - NEW_TYPING = sys.version_info[:3] >= (3, 7, 0) # PEP 560 +if NEW_TYPING: + import collections.abc if NEW_TYPING: - from typing import Callable, Union, TypeVar, ClassVar, Tuple, _GenericAlias + from typing import Generic, Callable, Union, TypeVar, ClassVar, Tuple, _GenericAlias else: from typing import ( Callable, CallableMeta, Union, _Union, TupleMeta, TypeVar, From 8a84f4c8472480505512064a15880a3f75b6b1d7 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Mon, 19 Mar 2018 22:47:54 +0000 Subject: [PATCH 03/13] Update tests and fix evaluate --- test_typing_inspect.py | 9 ++++++++- typing_inspect.py | 10 +++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/test_typing_inspect.py b/test_typing_inspect.py index b94763c..4e4afd9 100644 --- a/test_typing_inspect.py +++ b/test_typing_inspect.py @@ -3,12 +3,15 @@ is_typevar, is_classvar, get_origin, get_parameters, get_last_args, get_args, get_generic_type, get_generic_bases, get_last_origin, ) -from unittest import TestCase, main +from unittest import TestCase, main, skipIf from typing import ( Union, ClassVar, Callable, Optional, TypeVar, Sequence, Mapping, MutableMapping, Iterable, Generic, List, Any, Dict, Tuple, NamedTuple, ) +import sys +NEW_TYPING = sys.version_info[:3] >= (3, 7, 0) # PEP 560 + class IsUtilityTestCase(TestCase): def sample_test(self, fun, samples, nonsamples): @@ -96,6 +99,7 @@ def test_parameters(self): self.assertEqual(get_parameters(Union[S_co, Tuple[T, T]][int, U]), (U,)) self.assertEqual(get_parameters(Mapping[T, Tuple[S_co, T]]), (T, S_co)) + @skipIf(NEW_TYPING) def test_last_args(self): T = TypeVar('T') S = TypeVar('S') @@ -107,6 +111,7 @@ def test_last_args(self): self.assertEqual(get_last_args(Callable[[T, S], int]), (T, S, int)) self.assertEqual(get_last_args(Callable[[], int]), (int,)) + @skipIf(NEW_TYPING) def test_args(self): T = TypeVar('T') self.assertEqual(get_args(Union[int, Tuple[T, int]][str]), @@ -114,6 +119,8 @@ def test_args(self): self.assertEqual(get_args(Union[int, Union[T, int], str][int]), (int, str)) self.assertEqual(get_args(int), ()) + + def test_args_evaluated(self): self.assertEqual(get_args(Union[int, Tuple[T, int]][str], evaluate=True), (int, Tuple[str, int])) self.assertEqual(get_args(Dict[int, Tuple[T, T]][Optional[int]], evaluate=True), diff --git a/typing_inspect.py b/typing_inspect.py index 8005d88..94acea8 100644 --- a/typing_inspect.py +++ b/typing_inspect.py @@ -257,11 +257,13 @@ def _eval_args(args): return tuple(res) -def get_args(tp, evaluate=False): +def get_args(tp, evaluate=None): """Get type arguments with all substitutions performed. For unions, basic simplifications used by Union constructor are performed. - If `evaluate` is False (default), report result as nested tuple, this matches - the internal representation of types. If `evaluate` is True, then all + On versions prior to 3.7 if `evaluate` is False (default), + report result as nested tuple, this matches + the internal representation of types. If `evaluate` is True + (or if Python version is 3.7 or greater), then all type parameters are applied (this could be time and memory expensive). Examples:: @@ -276,6 +278,8 @@ def get_args(tp, evaluate=False): get_args(Callable[[], T][int], evaluate=True) == ([], int,) """ if NEW_TYPING: + if evaluate=False: + raise ValueError('evaluate can only be True in Python 3.7') if isinstance(tp, _GenericAlias): return tp.__args__ return () From ae6b94663eb352db84379ec7fefac0474e83858e Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Mon, 19 Mar 2018 22:49:57 +0000 Subject: [PATCH 04/13] Fix syntax error --- typing_inspect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typing_inspect.py b/typing_inspect.py index 94acea8..5e6eb5f 100644 --- a/typing_inspect.py +++ b/typing_inspect.py @@ -278,7 +278,7 @@ def get_args(tp, evaluate=None): get_args(Callable[[], T][int], evaluate=True) == ([], int,) """ if NEW_TYPING: - if evaluate=False: + if not evaluate: raise ValueError('evaluate can only be True in Python 3.7') if isinstance(tp, _GenericAlias): return tp.__args__ From b0411dfa15807eee1c613414acd377bf6836e9e3 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Mon, 19 Mar 2018 22:51:47 +0000 Subject: [PATCH 05/13] Add reason for skipping tests --- test_typing_inspect.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test_typing_inspect.py b/test_typing_inspect.py index 4e4afd9..59f4422 100644 --- a/test_typing_inspect.py +++ b/test_typing_inspect.py @@ -99,7 +99,7 @@ def test_parameters(self): self.assertEqual(get_parameters(Union[S_co, Tuple[T, T]][int, U]), (U,)) self.assertEqual(get_parameters(Mapping[T, Tuple[S_co, T]]), (T, S_co)) - @skipIf(NEW_TYPING) + @skipIf(NEW_TYPING, "Not supported in Python 3.7") def test_last_args(self): T = TypeVar('T') S = TypeVar('S') @@ -111,7 +111,7 @@ def test_last_args(self): self.assertEqual(get_last_args(Callable[[T, S], int]), (T, S, int)) self.assertEqual(get_last_args(Callable[[], int]), (int,)) - @skipIf(NEW_TYPING) + @skipIf(NEW_TYPING, "Not supported in Python 3.7") def test_args(self): T = TypeVar('T') self.assertEqual(get_args(Union[int, Tuple[T, int]][str]), From 64cc6b4b7640b581758808cdbf9e93e84ceaa295 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Mon, 19 Mar 2018 22:56:03 +0000 Subject: [PATCH 06/13] Fix some tests --- test_typing_inspect.py | 2 ++ typing_inspect.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test_typing_inspect.py b/test_typing_inspect.py index 59f4422..9cdf317 100644 --- a/test_typing_inspect.py +++ b/test_typing_inspect.py @@ -69,6 +69,7 @@ def test_classvar(self): class GetUtilityTestCase(TestCase): + @skipIf(NEW_TYPING, "Not supported in Python 3.7") def test_last_origin(self): T = TypeVar('T') self.assertEqual(get_last_origin(int), None) @@ -121,6 +122,7 @@ def test_args(self): self.assertEqual(get_args(int), ()) def test_args_evaluated(self): + T = TypeVar('T') self.assertEqual(get_args(Union[int, Tuple[T, int]][str], evaluate=True), (int, Tuple[str, int])) self.assertEqual(get_args(Dict[int, Tuple[T, T]][Optional[int]], evaluate=True), diff --git a/typing_inspect.py b/typing_inspect.py index 5e6eb5f..bc21672 100644 --- a/typing_inspect.py +++ b/typing_inspect.py @@ -204,7 +204,7 @@ def get_parameters(tp): get_parameters(Mapping[T, Tuple[S_co, T]]) == (T, S_co) """ if NEW_TYPING: - if isinstance(tp, _GenericAlias) or issubclass(tp, Generic): + if isinstance(tp, _GenericAlias) or issubclass(tp, Generic) and tp is not Generic: return tp.__parameters__ return () if ( From aebd433a07d010b0f8b60f7f345503d465e47d1e Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Mon, 19 Mar 2018 23:03:22 +0000 Subject: [PATCH 07/13] Fix more tests --- typing_inspect.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/typing_inspect.py b/typing_inspect.py index bc21672..f0efa2d 100644 --- a/typing_inspect.py +++ b/typing_inspect.py @@ -176,7 +176,7 @@ def get_origin(tp): """ if NEW_TYPING: if isinstance(tp, _GenericAlias): - return tp.__origin__ + return tp.__origin__ if tp.__origin__ is not ClassVar else None if tp is Generic: return Generic return None @@ -204,7 +204,7 @@ def get_parameters(tp): get_parameters(Mapping[T, Tuple[S_co, T]]) == (T, S_co) """ if NEW_TYPING: - if isinstance(tp, _GenericAlias) or issubclass(tp, Generic) and tp is not Generic: + if isinstance(tp, _GenericAlias) or isinstance(tp, type) and issubclass(tp, Generic) and tp is not Generic: return tp.__parameters__ return () if ( @@ -281,7 +281,10 @@ def get_args(tp, evaluate=None): if not evaluate: raise ValueError('evaluate can only be True in Python 3.7') if isinstance(tp, _GenericAlias): - return tp.__args__ + res = tp.__args__ + if get_origin(tp) is collections.abc.Callable and res[0] is not Ellipsis: + res = (list(res[:-1]), res[-1]) + return res return () if is_classvar(tp): return (tp.__type__,) From 9968660635578c93425b403691aa3870a17091dd Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Mon, 19 Mar 2018 23:12:54 +0000 Subject: [PATCH 08/13] Two more fixes --- typing_inspect.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/typing_inspect.py b/typing_inspect.py index f0efa2d..f92225e 100644 --- a/typing_inspect.py +++ b/typing_inspect.py @@ -76,7 +76,8 @@ class MyClass(Callable[[int], int]): get_origin(tp) is Callable """ if NEW_TYPING: - return tp is Callable or isinstance(tp, _GenericAlias) and tp.__origin__ is collections.abc.Callable + return (tp is Callable or isinstance(tp, _GenericAlias) and tp.__origin__ is collections.abc.Callable or + isinstance(tp, type) and issubclass(tp, Generic) and issubclass(tp, collections.abc.Callable)) return type(tp) is CallableMeta @@ -99,7 +100,8 @@ class MyClass(Tuple[str, int]): get_origin(tp) is Tuple """ if NEW_TYPING: - return tp is Tuple or isinstance(tp, _GenericAlias) and tp.__origin__ is tuple + return (tp is Tuple or isinstance(tp, _GenericAlias) and tp.__origin__ is tuple or + isinstance(tp, type) and issubclass(tp, Generic) and issubclass(tp, tuple)) return type(tp) is TupleMeta From 30ab0afc35eb8bf6f9f399b3fcbc23e2720b12e9 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Mon, 19 Mar 2018 23:15:57 +0000 Subject: [PATCH 09/13] Two more fixes --- test_typing_inspect.py | 2 +- typing_inspect.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test_typing_inspect.py b/test_typing_inspect.py index 9cdf317..c9391e9 100644 --- a/test_typing_inspect.py +++ b/test_typing_inspect.py @@ -85,7 +85,7 @@ def test_origin(self): self.assertEqual(get_origin(ClassVar[int]), None) self.assertEqual(get_origin(Generic), Generic) self.assertEqual(get_origin(Generic[T]), Generic) - self.assertEqual(get_origin(List[Tuple[T, T]][int]), List) + self.assertEqual(get_origin(List[Tuple[T, T]][int]), list if NEW_TYPING else List) def test_parameters(self): T = TypeVar('T') diff --git a/typing_inspect.py b/typing_inspect.py index f92225e..8d13b61 100644 --- a/typing_inspect.py +++ b/typing_inspect.py @@ -51,7 +51,7 @@ def is_generic_type(tp): is_generic_type(Sequence[Union[str, bytes]]) == True """ if NEW_TYPING: - return isinstance(tp, Generic) or isinstance(tp, _GenericAlias) + return isinstance(tp, type) and issubclass(tp, Generic) or isinstance(tp, _GenericAlias) return (isinstance(tp, GenericMeta) and not isinstance(tp, (CallableMeta, TupleMeta))) From ce52d9013d4dca688123d7d501eb9662351b0592 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Mon, 19 Mar 2018 23:19:53 +0000 Subject: [PATCH 10/13] One more fix --- typing_inspect.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/typing_inspect.py b/typing_inspect.py index 8d13b61..b9839c3 100644 --- a/typing_inspect.py +++ b/typing_inspect.py @@ -51,7 +51,9 @@ def is_generic_type(tp): is_generic_type(Sequence[Union[str, bytes]]) == True """ if NEW_TYPING: - return isinstance(tp, type) and issubclass(tp, Generic) or isinstance(tp, _GenericAlias) + return (isinstance(tp, type) and issubclass(tp, Generic) or + isinstance(tp, _GenericAlias) and tp.__origin__ not in (Union, tuple, ClassVar, + collections.abc.Callable)) return (isinstance(tp, GenericMeta) and not isinstance(tp, (CallableMeta, TupleMeta))) From 9c568eed58350e3cd9a85477f3f8e710a62e81ad Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Tue, 20 Mar 2018 21:52:54 +0000 Subject: [PATCH 11/13] Fix docstrings; wrap long lines --- typing_inspect.py | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/typing_inspect.py b/typing_inspect.py index b9839c3..abb7ce3 100644 --- a/typing_inspect.py +++ b/typing_inspect.py @@ -14,7 +14,9 @@ if NEW_TYPING: - from typing import Generic, Callable, Union, TypeVar, ClassVar, Tuple, _GenericAlias + from typing import ( + Generic, Callable, Union, TypeVar, ClassVar, Tuple, _GenericAlias + ) else: from typing import ( Callable, CallableMeta, Union, _Union, TupleMeta, TypeVar, @@ -52,8 +54,8 @@ def is_generic_type(tp): """ if NEW_TYPING: return (isinstance(tp, type) and issubclass(tp, Generic) or - isinstance(tp, _GenericAlias) and tp.__origin__ not in (Union, tuple, ClassVar, - collections.abc.Callable)) + isinstance(tp, _GenericAlias) and + tp.__origin__ not in (Union, tuple, ClassVar, collections.abc.Callable)) return (isinstance(tp, GenericMeta) and not isinstance(tp, (CallableMeta, TupleMeta))) @@ -75,11 +77,13 @@ class MyClass(Callable[[int], int]): For more general tests use callable(), for more precise test (excluding subclasses) use:: - get_origin(tp) is Callable + get_origin(tp) is collections.abc.Callable # Callable prior to Python 3.7 """ if NEW_TYPING: - return (tp is Callable or isinstance(tp, _GenericAlias) and tp.__origin__ is collections.abc.Callable or - isinstance(tp, type) and issubclass(tp, Generic) and issubclass(tp, collections.abc.Callable)) + return (tp is Callable or isinstance(tp, _GenericAlias) and + tp.__origin__ is collections.abc.Callable or + isinstance(tp, type) and issubclass(tp, Generic) and + issubclass(tp, collections.abc.Callable)) return type(tp) is CallableMeta @@ -99,11 +103,13 @@ class MyClass(Tuple[str, int]): For more general tests use issubclass(..., tuple), for more precise test (excluding subclasses) use:: - get_origin(tp) is Tuple + get_origin(tp) is tuple # Tuple prior to Python 3.7 """ if NEW_TYPING: - return (tp is Tuple or isinstance(tp, _GenericAlias) and tp.__origin__ is tuple or - isinstance(tp, type) and issubclass(tp, Generic) and issubclass(tp, tuple)) + return (tp is Tuple or isinstance(tp, _GenericAlias) and + tp.__origin__ is tuple or + isinstance(tp, type) and issubclass(tp, Generic) and + issubclass(tp, tuple)) return type(tp) is TupleMeta @@ -116,7 +122,8 @@ def is_union_type(tp): is_union_type(Union[T, int]) == True """ if NEW_TYPING: - return tp is Union or isinstance(tp, _GenericAlias) and tp.__origin__ is Union + return (tp is Union or + isinstance(tp, _GenericAlias) and tp.__origin__ is Union) return type(tp) is _Union @@ -140,7 +147,8 @@ def is_classvar(tp): is_classvar(ClassVar[List[T]]) == True """ if NEW_TYPING: - return tp is ClassVar or isinstance(tp, _GenericAlias) and tp.__origin__ is ClassVar + return (tp is ClassVar or + isinstance(tp, _GenericAlias) and tp.__origin__ is ClassVar) return type(tp) is _ClassVar @@ -157,7 +165,8 @@ def get_last_origin(tp): get_last_origin(List) == List """ if NEW_TYPING: - raise ValueError('This function is only supported in Python 3.6, use get_origin instead') + raise ValueError('This function is only supported in Python 3.6,' + ' use get_origin instead') sentinel = object() origin = getattr(tp, '__origin__', sentinel) if origin is sentinel: @@ -176,7 +185,7 @@ def get_origin(tp): get_origin(Generic) == Generic get_origin(Generic[T]) == Generic get_origin(Union[T, int]) == Union - get_origin(List[Tuple[T, T]][int]) == List + get_origin(List[Tuple[T, T]][int]) == list # List prior to Python 3.7 """ if NEW_TYPING: if isinstance(tp, _GenericAlias): @@ -208,7 +217,9 @@ def get_parameters(tp): get_parameters(Mapping[T, Tuple[S_co, T]]) == (T, S_co) """ if NEW_TYPING: - if isinstance(tp, _GenericAlias) or isinstance(tp, type) and issubclass(tp, Generic) and tp is not Generic: + if (isinstance(tp, _GenericAlias) or + isinstance(tp, type) and issubclass(tp, Generic) and + tp is not Generic): return tp.__parameters__ return () if ( @@ -232,7 +243,8 @@ def get_last_args(tp): get_last_args(Callable[[], int]) == (int,) """ if NEW_TYPING: - raise ValueError('This function is only supported in Python 3.6, use get_args instead') + raise ValueError('This function is only supported in Python 3.6,' + ' use get_args instead') if is_classvar(tp): return (tp.__type__,) if tp.__type__ is not None else () if ( From d09bbeebd22f19e66d3004f5b564cbb9bb86d1b8 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Tue, 20 Mar 2018 22:11:13 +0000 Subject: [PATCH 12/13] Allow evaluate to be absent --- typing_inspect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typing_inspect.py b/typing_inspect.py index abb7ce3..4f0fb37 100644 --- a/typing_inspect.py +++ b/typing_inspect.py @@ -294,7 +294,7 @@ def get_args(tp, evaluate=None): get_args(Callable[[], T][int], evaluate=True) == ([], int,) """ if NEW_TYPING: - if not evaluate: + if evaluare is not None and not evaluate: raise ValueError('evaluate can only be True in Python 3.7') if isinstance(tp, _GenericAlias): res = tp.__args__ From 9935dc81bed86892a5a902fdea1dca5be4afada1 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Tue, 20 Mar 2018 22:18:18 +0000 Subject: [PATCH 13/13] Fix a typo --- typing_inspect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typing_inspect.py b/typing_inspect.py index 4f0fb37..957c6c3 100644 --- a/typing_inspect.py +++ b/typing_inspect.py @@ -294,7 +294,7 @@ def get_args(tp, evaluate=None): get_args(Callable[[], T][int], evaluate=True) == ([], int,) """ if NEW_TYPING: - if evaluare is not None and not evaluate: + if evaluate is not None and not evaluate: raise ValueError('evaluate can only be True in Python 3.7') if isinstance(tp, _GenericAlias): res = tp.__args__