FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix decorated methods with self-types in protocols by ilevkivskyi · Pull Request #19484 · python/mypy · GitHub

Repository navigation

Fix decorated methods with self-types in protocols - #19484

Merged
ilevkivskyi merged 1 commit into
python:masterfrom
ilevkivskyi:fix-proto-self-dec
Jul 21, 2025
Merged

ilevkivskyi merged 1 commit into
python:masterfrom
ilevkivskyi:fix-proto-self-dec

Conversation

ilevkivskyi commented Jul 20, 2025 •
edited
Loading

Copy link
Copy Markdown
Member

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
Copy Markdown
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]

Copy link
Copy Markdown
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 merged commit d528707 into python:master Jul 21, 2025
ilevkivskyi deleted the fix-proto-self-dec branch July 21, 2025 18:31
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL