mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
[3.13] typing: Add missing test case for Protocol inheritance (GH-132597) (#132603)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
parent
ff3f6588c3
commit
88d95c3529
1 changed files with 17 additions and 0 deletions
|
@ -2935,6 +2935,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