Skip to content

Commit 5ed17e5

Browse files
author
Guido van Rossum
committed
Merge branch 'master' into new_generic (Fix #192).
2 parents 44a0488 + 238502e commit 5ed17e5

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎src/test_typing.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,9 @@ def foo(x: T):
756756
assert type(a) is Node
757757
assert type(b) is Node
758758
assert type(c) is Node
759+
assert a.label == x
760+
assert b.label == x
761+
assert c.label == x
759762

760763
foo(42)
761764

‎src/typing.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,13 +1079,19 @@ def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
10791079

10801080
__slots__ = ()
10811081

1082+
# TODO: GenericMeta should compute next_in_mro and stuff its
1083+
# __new__ in the class dict, if origin is cls. Issue #196.
10821084
def __new__(cls, *args, **kwds):
10831085
next_in_mro = object
10841086
# Look for the last occurrence of Generic or Generic[...].
10851087
for i, c in enumerate(cls.__mro__[:-1]):
10861088
if isinstance(c, GenericMeta) and _gorg(c) is Generic:
10871089
next_in_mro = cls.__mro__[i+1]
1088-
return next_in_mro.__new__(_gorg(cls))
1090+
origin = _gorg(cls)
1091+
obj = next_in_mro.__new__(origin)
1092+
if origin is not cls:
1093+
obj.__init__(*args, **kwds)
1094+
return obj
10891095

10901096

10911097
def cast(typ, val):

0 commit comments

Comments
 (0)