typing: Add missing test case for Protocol inheritance (#132597)

This commit is contained in:
Jelle Zijlstra 2025-04-16 08:21:27 -07:00 committed by GitHub
parent 71af090e24
commit 72da4a4458
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View 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