Skip to content

Commit ff6435a

Browse files
mvanhornclaude
andcommitted
gh-145688: Use identity check instead of name+module allowlist
Per @AlexWaygood's review, checking base.__module__ in {'typing', 'typing_extensions'} is fragile and would break third-party libraries like beartype that define their own Protocol using _ProtocolMeta. Use `base is Protocol or base is Generic` instead, which is the same pattern already used at line 1176 in _generic_class_getitem. This precisely targets the two base classes we want to skip without affecting any third-party Protocol implementations. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 42c3750 commit ff6435a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Lib/typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1884,7 +1884,7 @@ def _get_protocol_attrs(cls):
18841884
"""
18851885
attrs = set()
18861886
for base in cls.__mro__[:-1]: # without object
1887-
if base.__name__ in {'Protocol', 'Generic'} and base.__module__ in {'typing', 'typing_extensions'}:
1887+
if base is Protocol or base is Generic:
18881888
continue
18891889
try:
18901890
annotations = base.__annotations__

0 commit comments

Comments
 (0)