@@ -3510,19 +3510,19 @@ def visit_op_expr(self, e: OpExpr) -> Type:
35103510
35113511 def literal_value_from_expr (
35123512 self , expr : Expression , typ : Type | None = None
3513- ) -> tuple [list [str | int ], str ] | None :
3513+ ) -> tuple [list [str | int ], str , bool ] | None :
35143514 if isinstance (expr , StrExpr ):
3515- return [expr .value ], "builtins.str"
3515+ return [expr .value ], "builtins.str" , False
35163516 if isinstance (expr , IntExpr ):
3517- return [expr .value ], "builtins.int"
3517+ return [expr .value ], "builtins.int" , False
35183518 if isinstance (expr , BytesExpr ):
3519- return [expr .value ], "builtins.bytes"
3519+ return [expr .value ], "builtins.bytes" , False
35203520
35213521 typ = typ or self .accept (expr )
35223522 ptype = get_proper_type (typ )
35233523
35243524 if isinstance (ptype , LiteralType ) and not isinstance (ptype .value , (bool , float )):
3525- return [ptype .value ], ptype .fallback .type .fullname
3525+ return [ptype .value ], ptype .fallback .type .fullname , True
35263526
35273527 if isinstance (ptype , UnionType ):
35283528 fallback : str | None = None
@@ -3538,15 +3538,19 @@ def literal_value_from_expr(
35383538 values .append (pitem .value )
35393539 else :
35403540 assert fallback is not None
3541- return values , fallback
3541+ return values , fallback , True
35423542 return None
35433543
35443544 def literal_expression_addition (self , e : OpExpr , left_type : Type ) -> Type | None :
35453545 """Check if literal values can be combined with addition."""
35463546 assert e .op == "+"
35473547 if not (lvalue := self .literal_value_from_expr (e .left , left_type )):
35483548 return None
3549- if not (rvalue := self .literal_value_from_expr (e .right )) or lvalue [1 ] != rvalue [1 ]:
3549+ if (
3550+ not (rvalue := self .literal_value_from_expr (e .right ))
3551+ or lvalue [1 ] != rvalue [1 ] # different fallback
3552+ or lvalue [2 ] + rvalue [2 ] == 0 # no LiteralType
3553+ ):
35503554 return None
35513555
35523556 values : list [int | str ] = sorted (
0 commit comments