@@ -3585,19 +3585,19 @@ def visit_op_expr(self, e: OpExpr) -> Type:
35853585
35863586 def literal_value_from_expr (
35873587 self , expr : Expression , typ : Type | None = None
3588- ) -> tuple [list [str | int ], str ] | None :
3588+ ) -> tuple [list [str | int ], str , bool ] | None :
35893589 if isinstance (expr , StrExpr ):
3590- return [expr .value ], "builtins.str"
3590+ return [expr .value ], "builtins.str" , False
35913591 if isinstance (expr , IntExpr ):
3592- return [expr .value ], "builtins.int"
3592+ return [expr .value ], "builtins.int" , False
35933593 if isinstance (expr , BytesExpr ):
3594- return [expr .value ], "builtins.bytes"
3594+ return [expr .value ], "builtins.bytes" , False
35953595
35963596 typ = typ or self .accept (expr )
35973597 ptype = get_proper_type (typ )
35983598
35993599 if isinstance (ptype , LiteralType ) and not isinstance (ptype .value , (bool , float )):
3600- return [ptype .value ], ptype .fallback .type .fullname
3600+ return [ptype .value ], ptype .fallback .type .fullname , True
36013601
36023602 if isinstance (ptype , UnionType ):
36033603 fallback : str | None = None
@@ -3613,15 +3613,19 @@ def literal_value_from_expr(
36133613 values .append (pitem .value )
36143614 else :
36153615 assert fallback is not None
3616- return values , fallback
3616+ return values , fallback , True
36173617 return None
36183618
36193619 def literal_expression_addition (self , e : OpExpr , left_type : Type ) -> Type | None :
36203620 """Check if literal values can be combined with addition."""
36213621 assert e .op == "+"
36223622 if not (lvalue := self .literal_value_from_expr (e .left , left_type )):
36233623 return None
3624- if not (rvalue := self .literal_value_from_expr (e .right )) or lvalue [1 ] != rvalue [1 ]:
3624+ if (
3625+ not (rvalue := self .literal_value_from_expr (e .right ))
3626+ or lvalue [1 ] != rvalue [1 ] # different fallback
3627+ or lvalue [2 ] + rvalue [2 ] == 0 # no LiteralType
3628+ ):
36253629 return None
36263630
36273631 values : list [int | str ] = sorted (
0 commit comments