Skip to content

[mypyc] Fix TypeError in lambda argument to overloaded function #12780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 13, 2022

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented May 13, 2022

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.

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Btw, maybe later we can use this to get rid of the type_overrides_set() (and type_overrides in general).

@JukkaL
Copy link
Collaborator Author

JukkaL commented May 13, 2022

Btw, maybe later we can use this to get rid of the type_overrides_set() (and type_overrides in general).

A good idea! I had totally forgotten about these.

@JukkaL JukkaL merged commit 5ceaf3d into master May 13, 2022
@JukkaL JukkaL deleted the mypyc-fix-overload branch May 13, 2022 12:38
@JukkaL JukkaL mentioned this pull request May 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants