Skip to content

Commit 365cb5b

Browse files
ilevkivskyiMariatta
authored andcommitted
bpo-28556: Fix regression that sneaked into recent typing updates (GH-270)
1 parent 6059ce4 commit 365cb5b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Lib/test/test_typing.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,14 @@ class D(C[T]):
701701
self.assertEqual(D.x, 'from derived x')
702702
self.assertEqual(D[str].z, 'from derived z')
703703

704+
def test_abc_registry_kept(self):
705+
T = TypeVar('T')
706+
class C(Generic[T]): ...
707+
C.register(int)
708+
self.assertIsInstance(1, C)
709+
C[int]
710+
self.assertIsInstance(1, C)
711+
704712
def test_false_subclasses(self):
705713
class MyMapping(MutableMapping[str, str]): pass
706714
self.assertNotIsInstance({}, MyMapping)

Lib/typing.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,10 @@ def __copy__(self):
11601160

11611161
def __setattr__(self, attr, value):
11621162
# We consider all the subscripted genrics as proxies for original class
1163-
if attr.startswith('__') and attr.endswith('__'):
1163+
if (
1164+
attr.startswith('__') and attr.endswith('__') or
1165+
attr.startswith('_abc_')
1166+
):
11641167
super(GenericMeta, self).__setattr__(attr, value)
11651168
else:
11661169
super(GenericMeta, _gorg(self)).__setattr__(attr, value)

0 commit comments

Comments
 (0)