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

Filter overload items based on self type during type inference by JukkaL · Pull Request #17873 · python/mypy · GitHub

Repository navigation

Filter overload items based on self type during type inference - #17873

Merged
JukkaL merged 11 commits into
masterfrom
fix-type-var-values
Oct 3, 2024
Merged

JukkaL merged 11 commits into
masterfrom
fix-type-var-values

Conversation

JukkaL commented Oct 3, 2024 •
edited
Loading

Copy link
Copy Markdown
Collaborator

Fix type argument inference for overloaded functions with explicit self types. Filter out the overload items based on the declared and actual types of self. The implementation is best effort and does the filtering only in simple cases, to reduce the risk of regressions (primarily performance, but I worry also about infinite recursion). I added a fast path for the typical case, since without it the filtering was quite expensive.

Note that the overload item filtering already worked in many contexts. This only improves it in specific contexts -- at least when inferring generic protocol compatibility.

This is a more localized (and thus lower-risk) fix compared to #14975 (thanks @tyralla!). #14975 might still be a good idea, but I'm not comfortable merging it now, and I want a quick fix to unblock the mypy 1.12 release.

Fixes #15031. Fixes #17863.

Co-authored by @tyralla.

JukkaL commented Oct 3, 2024

Copy link
Copy Markdown
Collaborator Author

I added a test case from #14975 by @tyralla.

JukkaL requested a review from ilevkivskyi October 3, 2024 13:34

ilevkivskyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yeah, looks hacky, but OK as a quick fix.

This comment has been minimized.

github-actions Bot commented Oct 3, 2024

Copy link
Copy Markdown
Contributor

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

discord.py (https://github.com/Rapptz/discord.py)
+ discord/ext/commands/help.py:668: error: Argument "key" to "sort" of "list" has incompatible type "Callable[[Command[Any, [VarArg(Any), KwArg(Any)], Any]], Any] | None"; expected "Callable[[Command[Any, [VarArg(Any), KwArg(Any)], Any]], SupportsDunderLT[Any] | SupportsDunderGT[Any]]"  [arg-type]

scipy (https://github.com/scipy/scipy)
- scipy/_lib/unuran/get_and_clean_unuran.py:55: error: Cannot infer type argument 1 of "copyfileobj"  [misc]

JukkaL commented Oct 3, 2024

Copy link
Copy Markdown
Collaborator Author

The new error in discord.py seems correct. We are now filtering the overloads of list.sort as expected.

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.

Regression: IO[str] not compatible with SupportsWrite[AnyStr] shutil.copyfileobj stopped working in 1.2.0

2 participants


Back | FazBrowse Home | New Git URL