Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p committed Oct 21, 2024
1 parent 7ddb4ae commit bf5b483
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3445,7 +3445,7 @@ def visit_op_expr(self, e: OpExpr) -> Type:
items=proper_left_type.items + [UnpackType(mapped)]
)

if e.op == "+" and (result := self.literal_expression_addition(e)):
if e.op == "+" and (result := self.literal_expression_addition(e, left_type)):
return result

use_reverse: UseReverse = USE_REVERSE_DEFAULT
Expand Down Expand Up @@ -3509,9 +3509,9 @@ def visit_op_expr(self, e: OpExpr) -> Type:
raise RuntimeError(f"Unknown operator {e.op}")

def literal_value_from_expr(
self, expr: Expression
self, expr: Expression, typ: Type | None = None
) -> tuple[str | int, str] | tuple[list[str | int], str] | None:
typ = self.accept(expr)
typ = typ or self.accept(expr)
ptype = get_proper_type(typ)

if isinstance(ptype, UnionType):
Expand Down Expand Up @@ -3542,8 +3542,8 @@ def literal_value_from_expr(
return ptype.value, ptype.fallback.type.fullname
return None

def literal_expression_addition(self, e: OpExpr) -> Type | None:
lvalue = self.literal_value_from_expr(e.left)
def literal_expression_addition(self, e: OpExpr, left_type: Type | None = None) -> Type | None:
lvalue = self.literal_value_from_expr(e.left, left_type)
rvalue = self.literal_value_from_expr(e.right)
if lvalue is not None and rvalue is not None and lvalue[1] == rvalue[1]:
if isinstance(lvalue[0], list) and not isinstance(rvalue[0], list):
Expand Down

0 comments on commit bf5b483

Please sign in to comment.