Skip to content

types overlap only if all type args match #9452

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
Sep 18, 2020

Conversation

JelleZijlstra
Copy link
Member

Fixes #9451

Description

Previously, generic types were considered overlapping as soon as the first type argument matched. Now, we check all type arguments.

Test Plan

The new test failed before my change and now passes.

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Comment on lines 339 to 341
# Or, to use a more concrete example, List[Union[A, B]] and List[Union[B, C]]
# would be considered partially overlapping since it's possible for both lists
# to contain only instances of B at runtime.
Copy link
Member

Choose a reason for hiding this comment

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

Looking at this example I am wondering if the original behavior wasn't intentional?

Copy link
Member Author

Choose a reason for hiding this comment

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

The example only has a single type argument; I think the case with multiple args was just not considered.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I stumbled a little on this too, unions are dealt with by the recursive call, about a hundred lines earlier in the function

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.

Looks this was an oversight in the original implementation.

@JelleZijlstra JelleZijlstra merged commit 44a9687 into python:master Sep 18, 2020
@JelleZijlstra JelleZijlstra deleted the overlap branch September 18, 2020 16:03
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.

Overload with Dict only checks overlap on keys
4 participants