]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
typing: Add missing test case for Protocol inheritance (#132597)
authorJelle Zijlstra <jelle.zijlstra@gmail.com>
Wed, 16 Apr 2025 15:21:27 +0000 (08:21 -0700)
committerGitHub <noreply@github.com>
Wed, 16 Apr 2025 15:21:27 +0000 (08:21 -0700)
Lib/test/test_typing.py

index 5b05ebe8702015a644d345f56d6881868efad2e3..32f12a3f8b22f104645e2839f5d9b0be8dd5dd36 100644 (file)
@@ -2933,6 +2933,23 @@ class ProtocolTests(BaseTestCase):
         self.assertNotIsInstance(D(), E)
         self.assertNotIsInstance(E(), D)
 
+    def test_inheritance_from_object(self):
+        # Inheritance from object is specifically allowed, unlike other nominal classes
+        class P(Protocol, object):
+            x: int
+
+        self.assertEqual(typing.get_protocol_members(P), {'x'})
+
+        class OldGeneric(Protocol, Generic[T], object):
+            y: T
+
+        self.assertEqual(typing.get_protocol_members(OldGeneric), {'y'})
+
+        class NewGeneric[T](Protocol, object):
+            z: T
+
+        self.assertEqual(typing.get_protocol_members(NewGeneric), {'z'})
+
     def test_no_instantiation(self):
         class P(Protocol): pass