Skip to content

Fix decorated methods with self-types in protocols #19484

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 1 commit into from
Jul 21, 2025

Conversation

ilevkivskyi
Copy link
Member

@ilevkivskyi ilevkivskyi commented Jul 20, 2025

Fixes #19482

The regression is caused by overlap of three problems (directly or indirectly):

  • Using mx.original_type instead of mx.self_type for expanding (not otherwise bound) self-types.
  • Having a weird special case for ... vs self-types in constraint inference.
  • Not refreshing type variable ids during protocol subtype checks (hack needed for technical reasons).

I fix the first one, and limit the blast radius of the second one.

Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

steam.py (https://github.com/Gobot1234/steam.py)
- steam/chat.py:402: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[Chat[ChatMessageT, ClanT, GroupT]]"; expected "type[Self]"  [arg-type]
+ steam/chat.py:402: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[Chat[ChatMessageT, ClanT, GroupT]]"; expected "type[Never]"  [arg-type]
- steam/chat.py:589: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[ChatGroup[MemberT, ChatT, ChatGroupTypeT]]"; expected "type[Self]"  [arg-type]
+ steam/chat.py:589: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[ChatGroup[MemberT, ChatT, ChatGroupTypeT]]"; expected "type[Never]"  [arg-type]
- steam/chat.py:608: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[ChatGroup[MemberT, ChatT, ChatGroupTypeT]]"; expected "type[Self]"  [arg-type]
+ steam/chat.py:608: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[ChatGroup[MemberT, ChatT, ChatGroupTypeT]]"; expected "type[Never]"  [arg-type]
- steam/chat.py:643: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[ChatGroup[MemberT, ChatT, ChatGroupTypeT]]"; expected "type[Self]"  [arg-type]
+ steam/chat.py:643: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[ChatGroup[MemberT, ChatT, ChatGroupTypeT]]"; expected "type[Never]"  [arg-type]
- steam/chat.py:688: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[ChatGroup[MemberT, ChatT, ChatGroupTypeT]]"; expected "type[Self]"  [arg-type]
+ steam/chat.py:688: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[ChatGroup[MemberT, ChatT, ChatGroupTypeT]]"; expected "type[Never]"  [arg-type]
- steam/chat.py:696: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[ChatGroup[MemberT, ChatT, ChatGroupTypeT]]"; expected "type[Self]"  [arg-type]
+ steam/chat.py:696: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[ChatGroup[MemberT, ChatT, ChatGroupTypeT]]"; expected "type[Never]"  [arg-type]
- steam/chat.py:869: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[ChatGroup[MemberT, ChatT, ChatGroupTypeT]]"; expected "type[Self]"  [arg-type]
+ steam/chat.py:869: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[ChatGroup[MemberT, ChatT, ChatGroupTypeT]]"; expected "type[Never]"  [arg-type]
+ steam/state.py:1470: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[GroupChannel]"; expected "type[Never]"  [arg-type]
+ steam/state.py:1470: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[ClanChannel]"; expected "type[Never]"  [arg-type]
+ steam/state.py:1509: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[GroupChannel]"; expected "type[Never]"  [arg-type]
+ steam/state.py:1509: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[ClanChannel]"; expected "type[Never]"  [arg-type]
+ steam/state.py:2277: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[Commentable]"; expected "type[Never]"  [arg-type]
+ steam/state.py:2289: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[Commentable]"; expected "type[Never]"  [arg-type]
+ steam/state.py:2304: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[OwnerT]"; expected "type[Never]"  [arg-type]
+ steam/state.py:2328: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[Commentable]"; expected "type[Never]"  [arg-type]
+ steam/state.py:2339: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[Commentable]"; expected "type[Never]"  [arg-type]
+ steam/state.py:2426: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[Awardable[int]]"; expected "type[Never]"  [arg-type]
- steam/state.py:2439: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[Awardable[int]]"; expected "type[type[Awardable[int]]]"  [arg-type]
+ steam/state.py:2439: error: Argument 2 to "__get__" of "classproperty" has incompatible type "type[Awardable[int]]"; expected "type[Never]"  [arg-type]

@ilevkivskyi
Copy link
Member Author

The mypy_primer looks correct. We never supported "capturing" generic callables in an instance type (this would require existential types or similar), except for a hack that only works with paramspecs.

@ilevkivskyi ilevkivskyi merged commit d528707 into python:master Jul 21, 2025
20 checks passed
@ilevkivskyi ilevkivskyi deleted the fix-proto-self-dec branch July 21, 2025 18:31
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.

False Positives in Protocol Assignability Check Where Self Is a Parameter of a Decorated Method (1.17.0)
3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy