Skip to content

Support protocol checks for self-types in tuple types#21535

Merged
ilevkivskyi merged 3 commits into
python:masterfrom
ilevkivskyi:proto-self-tup
May 22, 2026
Merged

Support protocol checks for self-types in tuple types#21535
ilevkivskyi merged 3 commits into
python:masterfrom
ilevkivskyi:proto-self-tup

Conversation

@ilevkivskyi
Copy link
Copy Markdown
Member

Fixes #21528

This fixes a regression caused by a typeshed PR exposing this missing feature. The implementation is somewhat non-trivial, but I don't see a simpler way to do it in a robust manner.

@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, just one minor comment about a comment.

Comment thread mypy/messages.py Outdated
if subtype.extra_attrs and subtype.extra_attrs.mod_name:
is_module = True
if not isinstance(original_subtype, TupleType):
# Only tuples are supported as implementing protocols for now.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment was a bit confusing. It seemed imply that only a tuple type can be a subtype of a protocol. Reword?

@github-actions
Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@ilevkivskyi ilevkivskyi merged commit 21e2859 into python:master May 22, 2026
25 checks passed
@ilevkivskyi ilevkivskyi deleted the proto-self-tup branch May 22, 2026 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[1.19 regression] copy.replace doesn't work with NamedTuple anymore

2 participants