Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1615,9 +1615,7 @@ def check_overload_call(self,
# a union of inferred callables because for example a call
# Union[int -> int, str -> str](Union[int, str]) is invalid and
# we don't want to introduce internal inconsistencies.
unioned_result = (make_simplified_union(list(returns),
context.line,
context.column),
unioned_result = (make_simplified_union(list(returns)),
self.combine_function_signatures(inferred_types))

# Step 3: We try checking each branch one-by-one.
Expand Down
2 changes: 1 addition & 1 deletion mypy/expandtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def visit_union_type(self, t: UnionType) -> Type:
# After substituting for type variables in t.items,
# some of the resulting types might be subtypes of others.
from mypy.typeops import make_simplified_union # asdf
return make_simplified_union(self.expand_types(t.items), t.line, t.column)
return make_simplified_union(self.expand_types(t.items))

def visit_partial_type(self, t: PartialType) -> Type:
return t
Expand Down
9 changes: 4 additions & 5 deletions mypy/typeops.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ def is_simple_literal(t: ProperType) -> bool:


def make_simplified_union(items: Sequence[Type],
line: int = -1, column: int = -1,
*, keep_erased: bool = False,
contract_literals: bool = True) -> ProperType:
"""Build union type with redundant union items removed.
Expand Down Expand Up @@ -397,7 +396,7 @@ def make_simplified_union(items: Sequence[Type],
if contract_literals and sum(isinstance(item, LiteralType) for item in simplified_set) > 1:
simplified_set = try_contracting_literals_in_union(simplified_set)

return UnionType.make_union(simplified_set, line, column)
return UnionType.make_union(simplified_set)


def _remove_redundant_union_items(items: List[ProperType], keep_erased: bool) -> List[ProperType]:
Expand Down Expand Up @@ -495,7 +494,7 @@ def true_only(t: Type) -> ProperType:
# The true version of a union type is the union of the true versions of its components
new_items = [true_only(item) for item in t.items]
can_be_true_items = [item for item in new_items if item.can_be_true]
return make_simplified_union(can_be_true_items, line=t.line, column=t.column)
return make_simplified_union(can_be_true_items)
else:
ret_type = _get_type_special_method_bool_ret_type(t)

Expand Down Expand Up @@ -530,7 +529,7 @@ def false_only(t: Type) -> ProperType:
# The false version of a union type is the union of the false versions of its components
new_items = [false_only(item) for item in t.items]
can_be_false_items = [item for item in new_items if item.can_be_false]
return make_simplified_union(can_be_false_items, line=t.line, column=t.column)
return make_simplified_union(can_be_false_items)
else:
ret_type = _get_type_special_method_bool_ret_type(t)

Expand All @@ -552,7 +551,7 @@ def true_or_false(t: Type) -> ProperType:

if isinstance(t, UnionType):
new_items = [true_or_false(item) for item in t.items]
return make_simplified_union(new_items, line=t.line, column=t.column)
return make_simplified_union(new_items)

new_t = copy_type(t)
new_t.can_be_true = new_t.can_be_true_default()
Expand Down