bpo-28556: Add a regression test to typing (GH-15396)
authorIvan Levkivskyi <levkivskyi@gmail.com>
Thu, 22 Aug 2019 17:48:01 +0000 (18:48 +0100)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 22 Aug 2019 17:48:01 +0000 (10:48 -0700)
This adds a regression test for the issue found in the Python 2 backport, see https://github.com/python/typing/issues/656

https://bugs.python.org/issue28556

Lib/test/test_typing.py

index ba001c3462fcf50985d96e9e0382b76dec33029e..ba0800fae90e301f9a123b0da9e73cc1f1ec2da1 100644 (file)
@@ -961,6 +961,23 @@ class ProtocolTests(BaseTestCase):
         self.assertIsInstance(C(1), P)
         self.assertIsInstance(C(1), PG)
 
+    def test_protocol_checks_after_subscript(self):
+        class P(Protocol[T]): pass
+        class C(P[T]): pass
+        class Other1: pass
+        class Other2: pass
+        CA = C[Any]
+
+        self.assertNotIsInstance(Other1(), C)
+        self.assertNotIsSubclass(Other2, C)
+
+        class D1(C[Any]): pass
+        class D2(C[Any]): pass
+        CI = C[int]
+
+        self.assertIsInstance(D1(), C)
+        self.assertIsSubclass(D2, C)
+
     def test_protocols_support_register(self):
         @runtime_checkable
         class P(Protocol):