Commit 5ceaf3d
authored
[mypyc] Fix TypeError in lambda argument to overloaded function (#12780)
Previously we could export an invalid type for a lambda passed to an
overloaded function. We find the matching overload variant by type checking
the arguments against all overload items. We exported types for lambdas
always from the final potential overload item, even if that wasn't the matching
one. This could result in mypyc adding invalid type coercions that could result in
bogus TypeErrors.
The fix is to store types inferred when looking for matching overload items
into temporary type maps, and only the type map from the matching item
gets merged into the exported types.
This doesn't fully solve the problem -- if there are Any types in the
arguments, we can still export invalid types. This should be enough to
unblock syncing typeshed (#12766). Typeshed started triggering the issue
in compiled mypy when re.sub was changed to an overloaded function.
Work on #12773.1 parent 8faf44a commit 5ceaf3d
6 files changed
Lines changed: 238 additions & 128 deletions
File tree
- mypyc/test-data
- mypy
- test-data/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2217 | 2217 | | |
2218 | 2218 | | |
2219 | 2219 | | |
2220 | | - | |
| 2220 | + | |
| 2221 | + | |
| 2222 | + | |
| 2223 | + | |
2221 | 2224 | | |
2222 | 2225 | | |
2223 | 2226 | | |
| |||
0 commit comments