Skip to content

Improve type inference special case that involves union with Any #10887

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 1 commit into from
Jul 28, 2021

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jul 28, 2021

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.

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.
@JukkaL JukkaL merged commit 7808e82 into master Jul 28, 2021
@JukkaL JukkaL deleted the type-inference-tweak branch July 28, 2021 14:57
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