Skip to content

Commit 72da4a4

Browse files
typing: Add missing test case for Protocol inheritance (#132597)
1 parent 71af090 commit 72da4a4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Lib/test/test_typing.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2933,6 +2933,23 @@ class E(C, BP): pass
29332933
self.assertNotIsInstance(D(), E)
29342934
self.assertNotIsInstance(E(), D)
29352935

2936+
def test_inheritance_from_object(self):
2937+
# Inheritance from object is specifically allowed, unlike other nominal classes
2938+
class P(Protocol, object):
2939+
x: int
2940+
2941+
self.assertEqual(typing.get_protocol_members(P), {'x'})
2942+
2943+
class OldGeneric(Protocol, Generic[T], object):
2944+
y: T
2945+
2946+
self.assertEqual(typing.get_protocol_members(OldGeneric), {'y'})
2947+
2948+
class NewGeneric[T](Protocol, object):
2949+
z: T
2950+
2951+
self.assertEqual(typing.get_protocol_members(NewGeneric), {'z'})
2952+
29362953
def test_no_instantiation(self):
29372954
class P(Protocol): pass
29382955

0 commit comments

Comments
 (0)