Skip to content
Merged
Changes from all commits
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
11 changes: 9 additions & 2 deletions mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2678,15 +2678,22 @@ def format_list(types: Sequence[Type]) -> str:
return ", ".join(format(typ) for typ in types)

def format_union_items(types: Sequence[Type]) -> list[str]:
formatted = [format(typ) for typ in types if format(typ) != "None"]
formatted = []
has_none = False
for typ in types:
item = format(typ)
if item == "None":
has_none = True
else:
formatted.append(item)
if len(formatted) > MAX_UNION_ITEMS and verbosity == 0:
more = len(formatted) - MAX_UNION_ITEMS // 2
formatted = formatted[: MAX_UNION_ITEMS // 2]
else:
more = 0
if more:
formatted.append(f"<{more} more items>")
if any(format(typ) == "None" for typ in types):
if has_none:
formatted.append("None")
return formatted

Expand Down
Loading