-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix narrowing information not propagated in assignment and boolean ex…
…pressions (#11207) Fixes #8925. Consider the following narrowing (more realistically with TypedDicts), and the current outcome: ```py class A: tag: Literal["A"] class B: tag: Literal["B"] abo: A | B | None if abo is not None and abo.tag == "A": reveal_type(abo.tag) # Type is Literal["A"] reveal_type(abo) # Type is A | B ``` The RHS of the comparison correctly takes into account the LHS, and the `abo.tag` expression is correctly narrowed based on it, but this does not propagate upward to then narrow `abo` to `A`. The problem is that `and`/`or/`not`/assignment expressions recurse using the `find_isinstance_check_helper` function, which omits the `propagate_up_typemap_info` calls that its parent function `find_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.
- Loading branch information
Showing
2 changed files
with
28 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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