Skip to content

Commit baf2d91

Browse files
author
Guido van Rossum
committed
Backport fix for #192 to Python 2. Remove optimistic TODO about #196.
1 parent 238502e commit baf2d91

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

python2/test_typing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,9 @@ def foo(x):
673673
assert type(a) is Node
674674
assert type(b) is Node
675675
assert type(c) is Node
676+
assert a.label == x
677+
assert b.label == x
678+
assert c.label == x
676679

677680
foo(42)
678681

python2/typing.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,11 @@ def __new__(cls, *args, **kwds):
10931093
for i, c in enumerate(cls.__mro__[:-1]):
10941094
if isinstance(c, GenericMeta) and _gorg(c) is Generic:
10951095
next_in_mro = cls.__mro__[i+1]
1096-
return next_in_mro.__new__(_gorg(cls))
1096+
origin = _gorg(cls)
1097+
obj = next_in_mro.__new__(origin)
1098+
if origin is not cls:
1099+
obj.__init__(*args, **kwds)
1100+
return obj
10971101

10981102

10991103
def cast(typ, val):

src/typing.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,8 +1069,6 @@ def lookup_name(mapping: Mapping[X, Y], key: X, default: Y) -> Y:
10691069

10701070
__slots__ = ()
10711071

1072-
# TODO: GenericMeta should compute next_in_mro and stuff its
1073-
# __new__ in the class dict, if origin is cls. Issue #196.
10741072
def __new__(cls, *args, **kwds):
10751073
next_in_mro = object
10761074
# Look for the last occurrence of Generic or Generic[...].

0 commit comments

Comments
 (0)