Skip to content

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

Merged
JukkaL merged 1 commit into
masterfrom
type-inference-tweak
Jul 28, 2021
Merged

JukkaL merged 1 commit into
masterfrom
type-inference-tweak

Conversation

@JukkaL

@JukkaL JukkaL commented Jul 28, 2021

Copy link
Copy Markdown
Collaborator

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