summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
diff options
context:
space:
mode:
authorIvan Levkivskyi <levkivskyi@gmail.com>2018-05-09 01:23:46 (GMT)
committerGitHub <noreply@github.com>2018-05-09 01:23:46 (GMT)
commit43d12a6bd82bd09ac189069fe1eb40cdbc10a58c (patch)
tree571c07dc83eb43ce93d4e3f12499f04c0ca84648 /Lib/typing.py
parent0904f766e116c269675317e11368a4d29eef0bc6 (diff)
downloadcpython-43d12a6bd82bd09ac189069fe1eb40cdbc10a58c.zip
cpython-43d12a6bd82bd09ac189069fe1eb40cdbc10a58c.tar.gz
cpython-43d12a6bd82bd09ac189069fe1eb40cdbc10a58c.tar.bz2
bpo-28556: Minor fixes for typing module (GH-6732)
This also fixes https://bugs.python.org/issue33420
Diffstat (limited to 'Lib/typing.py')
-rw-r--r--Lib/typing.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index 8329607..89b73db 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -607,7 +607,8 @@ class TypeVar(_Final, _Immutable, _root=True):
# * __parameters__ is a tuple of unique free type parameters of a generic
# type, for example, Dict[T, T].__parameters__ == (T,);
# * __origin__ keeps a reference to a type that was subscripted,
-# e.g., Union[T, int].__origin__ == Union;
+# e.g., Union[T, int].__origin__ == Union, or the non-generic version of
+# the type.
# * __args__ is a tuple of all arguments used in subscripting,
# e.g., Dict[T, int].__args__ == (T, int).
@@ -835,7 +836,11 @@ class Generic:
if cls is Generic:
raise TypeError("Type Generic cannot be instantiated; "
"it can be used only as a base class")
- return super().__new__(cls)
+ if super().__new__ is object.__new__:
+ obj = super().__new__(cls)
+ else:
+ obj = super().__new__(cls, *args, **kwds)
+ return obj
@_tp_cache
def __class_getitem__(cls, params):
@@ -1385,6 +1390,7 @@ class NamedTupleMeta(type):
"follow default field(s) {default_names}"
.format(field_name=field_name,
default_names=', '.join(defaults_dict.keys())))
+ nm_tpl.__new__.__annotations__ = collections.OrderedDict(types)
nm_tpl.__new__.__defaults__ = tuple(defaults)
nm_tpl._field_defaults = defaults_dict
# update from user namespace without overriding special namedtuple attributes