X Tutup
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4574,6 +4574,19 @@ def c(self) -> int: return 5
with self.assertRaisesRegex(TypeError, "not a Protocol"):
get_protocol_members(ConcreteInherit())

def test_get_protocol_members_named_protocol_or_generic(self):
# gh-145688: Protocols named "Protocol" or "Generic" should still
# have their members collected correctly.
class Protocol(typing.Protocol):
a: int

self.assertEqual(get_protocol_members(Protocol), {'a'})

class Generic(typing.Protocol):
b: str

self.assertEqual(get_protocol_members(Generic), {'b'})

def test_is_protocol(self):
self.assertTrue(is_protocol(Proto))
self.assertTrue(is_protocol(Point))
Expand Down
2 changes: 1 addition & 1 deletion Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1884,7 +1884,7 @@ def _get_protocol_attrs(cls):
"""
attrs = set()
for base in cls.__mro__[:-1]: # without object
if base.__name__ in {'Protocol', 'Generic'}:
if base is Protocol or base is Generic:
continue
try:
annotations = base.__annotations__
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed :func:`typing.get_protocol_members` returning empty results for
:class:`typing.Protocol` subclasses named ``"Protocol"`` or ``"Generic"``.
Loading
X Tutup