Skip to content

Use (simplified) unions instead of joins for tuple fallbacks #17408

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 7 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use simpler wording
  • Loading branch information
ilevkivskyi committed Jun 22, 2024
commit 18c921e6412322fc652c16f25b8549d4f182d1c4
4 changes: 3 additions & 1 deletion mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3212,7 +3212,9 @@ def append_union_note(
non_matching.append(item)
if non_matching:
types = ", ".join([format_type(typ, options) for typ in non_matching])
notes.append(f"Subtype item{plural_s(types)} that may cause the mismatch: {types}")
notes.append(
f"Item{plural_s(non_matching)} in the first union not in the second: {types}"
)
return notes


Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-unions.test
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@ class C10: ...
x: Union[C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, int]
y: Union[C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, str]
x = y # E: Incompatible types in assignment (expression has type "Union[C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, str]", variable has type "Union[C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, int]") \
# N: Subtype items that may cause the mismatch: "str"
# N: Item in the first union not in the second: "str"

[case testLargeUnionsNoneShown]
from typing import Union
Expand All @@ -1345,4 +1345,4 @@ class C11: ...
x: Union[C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11]
y: Union[C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, None]
x = y # E: Incompatible types in assignment (expression has type "Union[C1, C2, C3, C4, C5, <6 more items>, None]", variable has type "Union[C1, C2, C3, C4, C5, <6 more items>]") \
# N: Subtype items that may cause the mismatch: "None"
# N: Item in the first union not in the second: "None"
Loading