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

Fix false negatives in walrus vs inference fallback logic by ilevkivskyi · Pull Request #20622 · python/mypy · GitHub

Repository navigation

Fix false negatives in walrus vs inference fallback logic - #20622

Merged
ilevkivskyi merged 1 commit into
python:masterfrom
ilevkivskyi:fix-walrus-inference
Jan 20, 2026
Merged

ilevkivskyi merged 1 commit into
python:masterfrom
ilevkivskyi:fix-walrus-inference

Conversation

Copy link
Copy Markdown
Member

Fixes #20606

This fixes couple edge cases where walrus interferes with type inference fallback logic. This is not a complete fix, but I think it is OK for now as these are probably rare situations. Most changes in binder.py are a pure performance optimization to compensate the fact that frame_context() will be more hot now. I also leave a TODO explaining a more proper fix for the assignment case (and other possible cases), return case should be already good (it is simpler since we don't need to apply any of the narrowing).

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 merged commit 32897bf into python:master Jan 20, 2026
23 checks passed
ilevkivskyi deleted the fix-walrus-inference branch January 20, 2026 12:30

hauntsaninja commented Jan 22, 2026 •
edited
Loading

Copy link
Copy Markdown
Collaborator

Looks like this is worth 2% on self check. https://github.com/mypyc/mypyc-benchmark-results/blob/master/reports/benchmarks/mypy_self_check.md

Maybe we can add some special case support for contextmanager in mypyc...

Copy link
Copy Markdown
Member Author

@hauntsaninja Yes, this is kind of a known thing. I raised priority for mypyc/mypyc#905

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.

[1.18 regression] False negative with variable increment in a walrus inside a tuple

2 participants


Back | FazBrowse Home | New Git URL