From: Jelle Zijlstra Date: Wed, 16 Apr 2025 15:21:27 +0000 (-0700) Subject: typing: Add missing test case for Protocol inheritance (#132597) X-Git-Tag: v3.14.0b1~451 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=72da4a445867648ee668bfc68a9bb659dfebe658;p=thirdparty%2FPython%2Fcpython.git typing: Add missing test case for Protocol inheritance (#132597) --- diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 5b05ebe87020..32f12a3f8b22 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -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