Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-132493: Avoid eager import of annotationlib in typing (again) #132596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 17, 2025
Prev Previous commit
Next Next commit
review
  • Loading branch information
JelleZijlstra committed Apr 16, 2025
commit f10143f5af96397f46ef0b19067208446fc3259b
1 change: 1 addition & 0 deletions 1 Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3137,6 +3137,7 @@ def test_lazy_evaluation_with_subprotocols(self):
class Base(Protocol):
x: int

@runtime_checkable
class Child(Base, Protocol):
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved
y: str

Expand Down
7 changes: 5 additions & 2 deletions 7 Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1925,9 +1925,11 @@ class _ProtocolMeta(ABCMeta):
# This metaclass is somewhat unfortunate,
# but is necessary for several reasons...
def __new__(mcls, name, bases, namespace, /, **kwargs):
is_protocol = False
if name == "Protocol" and bases == (Generic,):
pass
elif Protocol in bases:
is_protocol = True
for base in bases:
if not (
base in {object, Generic}
Expand All @@ -1942,7 +1944,8 @@ def __new__(mcls, name, bases, namespace, /, **kwargs):
f"got {base!r}"
)
cls = super().__new__(mcls, name, bases, namespace, **kwargs)
cls.__protocol_attrs_cache__ = None
if is_protocol:
cls.__protocol_attrs_cache__ = None
return cls

def __subclasscheck__(cls, other):
Expand Down Expand Up @@ -2015,7 +2018,7 @@ def __protocol_attrs__(cls):
def __non_callable_proto_members__(cls):
# PEP 544 prohibits using issubclass()
# with protocols that have non-method members.
non_callable_members = cls.__non_callable_proto_members_cache__
non_callable_members = cls.__non_callable_proto_members_cache__ # set by @runtime_checkable
if non_callable_members is None:
non_callable_members = set()
for attr in cls.__protocol_attrs__:
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.