Skip to content
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

Fix crash on lambda in generic context with generic method in body #15155

Merged
merged 2 commits into from
May 2, 2023

Conversation

ilevkivskyi
Copy link
Member

Fixes #15060

The example in the issue contains another case where an erased type may legitimately appear in a generic function. Namely, when we have a lambda in a generic context, and its body contains a call to a generic method. First, since we infer the type of lambda in erased context, some of lambda parameters may get assigned a type containing erased components. Then, when accessing a generic method on such type we may get a callable that is both generic and has erased components, thus causing the crash (actually there are two very similar crashes depending on the details of the generic method).

Provided that we now have two legitimate cases for erased type appearing in expand_type(), and special-casing (enabling) them would be tricky (a lot of functions will need to have allow_erased_callables), I propose to simply remove the check.

@ilevkivskyi ilevkivskyi requested a review from JukkaL April 28, 2023 23:16
@ilevkivskyi
Copy link
Member Author

@hauntsaninja FYI "Comment with mypy_primer diff" workflow failed with SyntaxError, see https://github.com/python/mypy/actions/runs/4835639818/jobs/8618116396

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Apr 29, 2023

Ugh, fixing #15156

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

graphql-core (https://github.com/graphql-python/graphql-core) got 1.05x slower (312.0s -> 329.1s)

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Sounds reasonable. Thanks!

@JukkaL JukkaL merged commit 9f69bea into python:master May 2, 2023
@ilevkivskyi ilevkivskyi deleted the fix-lambda-crash branch May 2, 2023 15:59
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.

Crash type-checking overloaded function
3 participants