Skip to content

Commit 4972202

Browse files
committed
Minor improvements
1 parent c399edf commit 4972202

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
@@ -3561,7 +3561,9 @@ def literal_expression_addition(self, e: OpExpr, left_type: Type) -> Type | None
35613561
)
35623562
if len(values) == 1:
35633563
return LiteralType(values[0], self.named_type(lvalue[1]))
3564-
return UnionType([LiteralType(val, self.named_type(lvalue[1])) for val in values])
3564+
return make_simplified_union(
3565+
[LiteralType(val, self.named_type(lvalue[1])) for val in values]
3566+
)
35653567

35663568
def visit_comparison_expr(self, e: ComparisonExpr) -> Type:
35673569
"""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
@@ -2968,17 +2968,17 @@ from typing_extensions import Literal
29682968
str_a: Literal["a"]
29692969
str_b: Literal["b"]
29702970
str_union_1: Literal["a", "b"]
2971-
str_union_2: Literal["c", "d"]
2971+
str_union_2: Literal["d", "c"]
29722972
s: str
29732973
int_1: Literal[1]
29742974
int_2: Literal[2]
29752975
int_union_1: Literal[1, 2]
2976-
int_union_2: Literal[3, 4]
2976+
int_union_2: Literal[4, 3]
29772977
i: int
29782978
bytes_a: Literal[b"a"]
29792979
bytes_b: Literal[b"b"]
29802980
bytes_union_1: Literal[b"a", b"b"]
2981-
bytes_union_2: Literal[b"c", b"d"]
2981+
bytes_union_2: Literal[b"d", b"c"]
29822982
b: bytes
29832983

29842984
misc_union: Literal["a", 1]

0 commit comments

Comments
 (0)