mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
typing: Add missing test case for Protocol inheritance (#132597)
This commit is contained in:
parent
71af090e24
commit
72da4a4458
1 changed files with 17 additions and 0 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue