Commit 7808e82
authored
Improve type inference special case that involves union with Any (#10887)
When trying to match `list[T]` and `list[str] | Any`, previously we
gave up, because the union items caused conflicting inferred values
for `T` (`str` and `Any`). Work around the issue by dropping `Any`
constraints if there are multiple sets of contraints, since we
prefer more precise types.
This fixes false positives resulting from python/typeshed#5557,
which changed some return types to contain unions with `Any` items.
See mypy primer results in #10881 for a real-world example of this
in sphinx.1 parent 10dc451 commit 7808e82
File tree
2 files changed
+18
-0
lines changed- mypy
- test-data/unit
2 files changed
+18
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
219 | 229 | | |
220 | 230 | | |
221 | 231 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1375 | 1375 | | |
1376 | 1376 | | |
1377 | 1377 | | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
0 commit comments