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
Improve Tuple/Sequence/Iterable overlapping #5315
Changes from 3 commits
a1ce0e1
859118a
d7e680b
8c0dda8
8fb14e4
5791783
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,9 +138,8 @@ class C(A, B): ... | |
|
||
# We must check for TupleTypes before Instances, since Tuple[A, ...] | ||
# is an Instance | ||
tup_overlap = is_overlapping_tuples(t, s, use_promotions) | ||
if tup_overlap is not None: | ||
return tup_overlap | ||
if is_overlapping_tuples(t, s, use_promotions): | ||
return True | ||
|
||
if isinstance(t, Instance): | ||
if isinstance(s, Instance): | ||
|
@@ -192,10 +191,10 @@ def is_overlapping_tuples(t: Type, s: Type, use_promotions: bool) -> Optional[bo | |
if all(is_overlapping_types(ti, si, use_promotions) | ||
for ti, si in zip(t.items, s.items)): | ||
return True | ||
# TupleType and non-tuples do not overlap | ||
return False | ||
# No tuples are involved here | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think getting rid of the I think this is probably hard to trigger because mypy doesn't ever really call
Previously, this used to reveal There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fixed this and added a regression test. Thank you for pointing this out. |
||
return None | ||
return is_subtype(t, s) or is_subtype(s, t) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Did you measure performance when this check is here or at the top of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was indeed measured from the top. I just added it after the object check. |
||
# TupleType and non-tuples are handled later | ||
# Otherwise, no tuples are involved | ||
return False | ||
|
||
|
||
def adjust_tuple(left: Type, r: Type) -> Optional[TupleType]: | ||
|
@@ -323,7 +322,8 @@ def visit_tuple_type(self, t: TupleType) -> Type: | |
return TupleType(items, t.fallback) | ||
# meet(Tuple[t1, t2, <...>], Tuple[s, ...]) == Tuple[meet(t1, s), meet(t2, s), <...>]. | ||
elif (isinstance(self.s, Instance) and | ||
self.s.type.fullname() == 'builtins.tuple' and self.s.args): | ||
(self.s.type.fullname() == 'builtins.tuple' or is_subtype(t, self.s)) | ||
and self.s.args): | ||
return t.copy_modified(items=[meet_types(it, self.s.args[0]) for it in t.items]) | ||
elif (isinstance(self.s, Instance) and t.fallback.type == self.s.type): | ||
# Uh oh, a broken named tuple type (https://github.com/python/mypy/issues/3016). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this change is now unnecessary (and the corresponding change below) after you added the check at the top of this function.