Fix narrowing information not propagated in assignment and boolean expressions #11207
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.
Description
Fixes #8925.
Consider the following narrowing (more realistically with TypedDicts),
and the current outcome:
The RHS of the comparison correctly takes into account the LHS, and the
abo.tag
expression is correctly narrowed based on it, but this doesnot propagate upward to then narrow
abo
toA
.The problem is that
and
/or
/not
/assignment expressions recurse usingthe
find_isinstance_check_helper
function, which omits thepropagate_up_typemap_info
calls that its parent functionfind_isinstance_check
performs.Fix this by replacing these recursive
find_isinstance_check_helper
calls with
find_isinstance_check
. This might not always be necessary,but I do not think that always propagating upwards should do any harm,
anyways.
Test Plan
Added a test case, fails before and passes after.