Repository navigation
Fix partial type assignment with walrus expressions - #22282
Closed
zhengguangzhuo wants to merge 2 commits into
Closed
zhengguangzhuo wants to merge 2 commits into
zhengguangzhuo wants to merge 2 commits into
Conversation
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: sphinx (https://github.com/sphinx-doc/sphinx)
- sphinx/builders/_epub_base.py:34:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
|
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #22262.
When a local variable starts as
Noneand an assignment's right-hand side contains a walrus assignment to that same variable, the walrus can resolve the variable's partial type while the outer assignment is being checked. The outer assignment then skips the compatibility check, allowing an incompatible value to pass silently.If evaluating the right-hand side has already resolved the partial type, check the inferred right-hand-side type against the variable's current type. Add a regression test for the reported tuple assignment.
Validation:
runtests.py check-python38.test— 63 passed.python -m mypy --config-file mypy_self_check.ini -p mypy— passed for 196 source files.git diff --check— passed.This change was prepared with AI assistance; the validation above was run locally.