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

Special-case unions in polymorphic inference #16461

Merged
merged 1 commit into from
Nov 13, 2023

Conversation

ilevkivskyi
Copy link
Member

Fixes #16451

This special-casing is unfortunate, but this is the best I came up so far.

Copy link
Contributor

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

discord.py (https://github.com/Rapptz/discord.py): typechecking got 1.08x slower (173.5s -> 186.8s)
(Performance measurements are based on a single noisy sample)

@ilevkivskyi ilevkivskyi mentioned this pull request Nov 11, 2023
2 tasks
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.

This looks a bit ad-hoc, but I can't propose a better way of solving the issue.

The use case that this supports seems sufficiently fundamental that it would be unfortunate not to support it. Empty mypy_primer output indicates that this is likely a net improvement. Looking for a more principled approach in the future would be nice, though.

@ilevkivskyi
Copy link
Member Author

@JukkaL Yeah. I was thinking about re-working union inference in general. But so far it seems to me whatever we do, we will need some kind of special-casing (at least for types like T | list[T]).

@ilevkivskyi ilevkivskyi merged commit fbb77c3 into python:master Nov 13, 2023
@ilevkivskyi ilevkivskyi deleted the union-poly branch November 13, 2023 16:22
JukkaL pushed a commit that referenced this pull request Nov 22, 2023
Fixes #16451

This special-casing is unfortunate, but this is the best I came up so
far.
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.

asynccontextmanager with TypeVar leads to new warnings (regression)
2 participants