]> granicus.if.org Git - python/commitdiff
bpo-28556: Fix regression that sneaked into recent typing updates (GH-270)
authorIvan Levkivskyi <levkivskyi@gmail.com>
Fri, 24 Feb 2017 17:28:26 +0000 (18:28 +0100)
committerMariatta <Mariatta@users.noreply.github.com>
Fri, 24 Feb 2017 17:28:26 +0000 (09:28 -0800)
Lib/test/test_typing.py
Lib/typing.py

index 3a82b595da5950aaf25c4a32d94578f8b55f1a5d..f0070ec975791ac0afd5afc1f787efb9c2938745 100644 (file)
@@ -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)
index fc2ed94cffd656306c2ede82710d3580fa4cf088..9a0f49099a3114565947901e82f597b097a8be12 100644 (file)
@@ -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)