Commit 689797a
authored
[ty] Type narrowing in comprehensions (#18934)
## Summary
Add type narrowing inside comprehensions:
```py
def _(xs: list[int | None]):
[reveal_type(x) for x in xs if x is not None] # revealed: int
```
closes astral-sh/ty#680
## Test Plan
* New Markdown tests
* Made sure the example from astral-sh/ty#680
now checks without errors
* Made sure that all removed ecosystem diagnostics were actually false
positives1 parent 66dbea9 commit 689797a
File tree
3 files changed
+26
-10
lines changed- crates/ty_python_semantic
- resources/mdtest/narrow/conditionals
- src
- semantic_index
- types
3 files changed
+26
-10
lines changedLines changed: 19 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
46 | 63 | | |
47 | 64 | | |
48 | 65 | | |
| |||
194 | 211 | | |
195 | 212 | | |
196 | 213 | | |
197 | | - | |
198 | | - | |
199 | | - | |
| 214 | + | |
200 | 215 | | |
201 | 216 | | |
202 | 217 | | |
| |||
276 | 291 | | |
277 | 292 | | |
278 | 293 | | |
279 | | - | |
280 | | - | |
| 294 | + | |
281 | 295 | | |
282 | 296 | | |
283 | 297 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
854 | 854 | | |
855 | 855 | | |
856 | 856 | | |
857 | | - | |
858 | | - | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
859 | 860 | | |
860 | 861 | | |
861 | 862 | | |
| |||
871 | 872 | | |
872 | 873 | | |
873 | 874 | | |
874 | | - | |
875 | | - | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
876 | 878 | | |
877 | 879 | | |
878 | 880 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5089 | 5089 | | |
5090 | 5090 | | |
5091 | 5091 | | |
5092 | | - | |
| 5092 | + | |
5093 | 5093 | | |
5094 | 5094 | | |
5095 | 5095 | | |
| |||
0 commit comments