Skip to content

Commit 42c3750

Browse files
mvanhornclaude
andcommitted
gh-145688: Handle typing_extensions.Protocol in _get_protocol_attrs
Address review feedback: also skip bases from typing_extensions module so the backported Protocol class is treated the same as typing.Protocol. Simplify NEWS entry to focus on user-visible behavior. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e0c8e43 commit 42c3750

2 files changed

Lines changed: 3 additions & 6 deletions

File tree

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__ == 'typing':
1887+
if base.__name__ in {'Protocol', 'Generic'} and base.__module__ in {'typing', 'typing_extensions'}:
18881888
continue
18891889
try:
18901890
annotations = base.__annotations__
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
Fixed :func:`typing.get_protocol_members` and :attr:`~typing.Protocol.__protocol_attrs__`
2-
returning empty results for Protocol subclasses named ``"Protocol"`` or ``"Generic"``.
3-
The check in :func:`_get_protocol_attrs` now uses identity comparison instead of
4-
name-based comparison to skip the base :class:`typing.Protocol` and
5-
:class:`typing.Generic` classes.
1+
Fixed :func:`typing.get_protocol_members` returning empty results for
2+
:class:`typing.Protocol` subclasses named ``"Protocol"`` or ``"Generic"``.

0 commit comments

Comments
 (0)