From 365cb5bb9069273e6970c9d5d17ee2fe5003e7ac Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Fri, 24 Feb 2017 18:28:26 +0100 Subject: bpo-28556: Fix regression that sneaked into recent typing updates (GH-270) --- Lib/test/test_typing.py | 8 ++++++++ Lib/typing.py | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 3a82b59..f0070ec 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -701,6 +701,14 @@ class GenericTests(BaseTestCase): self.assertEqual(D.x, 'from derived x') self.assertEqual(D[str].z, 'from derived z') + def test_abc_registry_kept(self): + T = TypeVar('T') + class C(Generic[T]): ... + C.register(int) + self.assertIsInstance(1, C) + C[int] + self.assertIsInstance(1, C) + def test_false_subclasses(self): class MyMapping(MutableMapping[str, str]): pass self.assertNotIsInstance({}, MyMapping) diff --git a/Lib/typing.py b/Lib/typing.py index fc2ed94..9a0f490 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -1160,7 +1160,10 @@ class GenericMeta(TypingMeta, abc.ABCMeta): def __setattr__(self, attr, value): # We consider all the subscripted genrics as proxies for original class - if attr.startswith('__') and attr.endswith('__'): + if ( + attr.startswith('__') and attr.endswith('__') or + attr.startswith('_abc_') + ): super(GenericMeta, self).__setattr__(attr, value) else: super(GenericMeta, _gorg(self)).__setattr__(attr, value) -- cgit v0.12