Skip to content

Commit c0c0a3f

Browse files
committed
Minor improvements
1 parent 9ead9fb commit c0c0a3f

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

mypy/checkexpr.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3636,7 +3636,9 @@ def literal_expression_addition(self, e: OpExpr, left_type: Type) -> Type | None
36363636
)
36373637
if len(values) == 1:
36383638
return LiteralType(values[0], self.named_type(lvalue[1]))
3639-
return UnionType([LiteralType(val, self.named_type(lvalue[1])) for val in values])
3639+
return make_simplified_union(
3640+
[LiteralType(val, self.named_type(lvalue[1])) for val in values]
3641+
)
36403642

36413643
def visit_comparison_expr(self, e: ComparisonExpr) -> Type:
36423644
"""Type check a comparison expression.

test-data/unit/check-literal.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2984,17 +2984,17 @@ from typing_extensions import Literal
29842984
str_a: Literal["a"]
29852985
str_b: Literal["b"]
29862986
str_union_1: Literal["a", "b"]
2987-
str_union_2: Literal["c", "d"]
2987+
str_union_2: Literal["d", "c"]
29882988
s: str
29892989
int_1: Literal[1]
29902990
int_2: Literal[2]
29912991
int_union_1: Literal[1, 2]
2992-
int_union_2: Literal[3, 4]
2992+
int_union_2: Literal[4, 3]
29932993
i: int
29942994
bytes_a: Literal[b"a"]
29952995
bytes_b: Literal[b"b"]
29962996
bytes_union_1: Literal[b"a", b"b"]
2997-
bytes_union_2: Literal[b"c", b"d"]
2997+
bytes_union_2: Literal[b"d", b"c"]
29982998
b: bytes
29992999

30003000
misc_union: Literal["a", 1]

0 commit comments

Comments
 (0)