Kaydet (Commit) 365cb5bb authored tarafından Ivan Levkivskyi's avatar Ivan Levkivskyi Kaydeden (comit) Mariatta

bpo-28556: Fix regression that sneaked into recent typing updates (GH-270)

üst 6059ce45
......@@ -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)
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment