Commit 2ba79cb
authored
Use union of current context and left side for right side narrowing of binary ops (#19249)
Fixes #12001. Fixes #6898. Fixes #15368. Improves #17790 and #11508.
When encountering `a {and,or} b`, we used to use `a` as primary context
for `b` inference. This results in weird errors when `a` and `b` are
completely unrelated, and in many cases return type/assignment type
context can do much better. Inferring to union should be harmless in
most cases, so use union of `a` and current context instead.1 parent 2996c91 commit 2ba79cb
File tree
2 files changed
+34
-1
lines changed- mypy
- test-data/unit
2 files changed
+34
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4288 | 4288 | | |
4289 | 4289 | | |
4290 | 4290 | | |
4291 | | - | |
| 4291 | + | |
| 4292 | + | |
| 4293 | + | |
4292 | 4294 | | |
4293 | 4295 | | |
4294 | 4296 | | |
| |||
5919 | 5921 | | |
5920 | 5922 | | |
5921 | 5923 | | |
| 5924 | + | |
| 5925 | + | |
| 5926 | + | |
| 5927 | + | |
| 5928 | + | |
| 5929 | + | |
| 5930 | + | |
| 5931 | + | |
| 5932 | + | |
| 5933 | + | |
5922 | 5934 | | |
5923 | 5935 | | |
5924 | 5936 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1510 | 1510 | | |
1511 | 1511 | | |
1512 | 1512 | | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
0 commit comments