Commit cb3bddd
Improve the support for promotions inside unions. (#19245)
Fixes #14987
I was puzzled as to why my previous attempts to avoid false
`unreachable` warnings for loops failed for issue #14987. After some
debugging, I realised that the underlying problem is that type narrowing
does not work with promotions if both the declared type and the
constraining type are unions:
```python
x: float | None
y: int | None
x = y
reveal_type(x) # None !!!
```
The fix seems straightforward (but let's see what the Mypy primer says)
and is checked by the test cases `testNarrowPromotionsInsideUnions1` and
`testNarrowPromotionsInsideUnions2`.
---------
Co-authored-by: Ivan Levkivskyi <[email protected]>1 parent 6600073 commit cb3bddd
2 files changed
+47
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
131 | 136 | | |
132 | 137 | | |
133 | | - | |
134 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
135 | 141 | | |
136 | 142 | | |
137 | 143 | | |
138 | 144 | | |
139 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
140 | 150 | | |
141 | | - | |
142 | | - | |
| 151 | + | |
| 152 | + | |
143 | 153 | | |
144 | 154 | | |
145 | 155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2446 | 2446 | | |
2447 | 2447 | | |
2448 | 2448 | | |
| 2449 | + | |
| 2450 | + | |
| 2451 | + | |
| 2452 | + | |
| 2453 | + | |
| 2454 | + | |
| 2455 | + | |
| 2456 | + | |
| 2457 | + | |
| 2458 | + | |
| 2459 | + | |
| 2460 | + | |
| 2461 | + | |
| 2462 | + | |
| 2463 | + | |
| 2464 | + | |
| 2465 | + | |
| 2466 | + | |
| 2467 | + | |
| 2468 | + | |
| 2469 | + | |
| 2470 | + | |
| 2471 | + | |
| 2472 | + | |
| 2473 | + | |
| 2474 | + | |
| 2475 | + | |
| 2476 | + | |
| 2477 | + | |
| 2478 | + | |
| 2479 | + | |
| 2480 | + | |
| 2481 | + | |
2449 | 2482 | | |
2450 | 2483 | | |
2451 | 2484 | | |
| |||
0 commit comments