Commit f3a37f7
committed
Fix narrowing information not propagated in assignment and boolean expressions
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.1 parent 8e82171 commit f3a37f7
2 files changed
+28
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4473 | 4473 | | |
4474 | 4474 | | |
4475 | 4475 | | |
4476 | | - | |
| 4476 | + | |
4477 | 4477 | | |
4478 | 4478 | | |
4479 | 4479 | | |
4480 | 4480 | | |
4481 | 4481 | | |
4482 | 4482 | | |
4483 | | - | |
| 4483 | + | |
4484 | 4484 | | |
4485 | 4485 | | |
4486 | 4486 | | |
| |||
4492 | 4492 | | |
4493 | 4493 | | |
4494 | 4494 | | |
4495 | | - | |
4496 | | - | |
| 4495 | + | |
| 4496 | + | |
4497 | 4497 | | |
4498 | 4498 | | |
4499 | 4499 | | |
4500 | 4500 | | |
4501 | 4501 | | |
4502 | 4502 | | |
4503 | | - | |
4504 | | - | |
| 4503 | + | |
| 4504 | + | |
4505 | 4505 | | |
4506 | 4506 | | |
4507 | 4507 | | |
4508 | 4508 | | |
4509 | 4509 | | |
4510 | 4510 | | |
4511 | | - | |
| 4511 | + | |
4512 | 4512 | | |
4513 | 4513 | | |
4514 | 4514 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
655 | 655 | | |
656 | 656 | | |
657 | 657 | | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
658 | 679 | | |
659 | 680 | | |
660 | 681 | | |
| |||
0 commit comments