Skip to content

Commit 308fbe8

Browse files
Update specialize.py
1 parent daabadd commit 308fbe8

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

mypyc/irbuild/specialize.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -748,10 +748,7 @@ def translate_fstring(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Va
748748
):
749749
items = expr.args[0].items
750750
for i, item in enumerate(items):
751-
if isinstance(item, StrExpr):
752-
continue
753-
elif isinstance(folded := constant_fold_expr(builder, item), str):
754-
items[i] = StrExpr(folded)
751+
if isinstance(item, StrExpr) or isinstance(constant_fold_expr(builder, item), str):
755752
continue
756753
elif isinstance(item, CallExpr):
757754
if not (
@@ -783,10 +780,8 @@ def translate_fstring(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Va
783780
def get_literal_str(expr: Expression) -> str | None:
784781
if isinstance(expr, StrExpr):
785782
return expr.value
786-
elif isinstance(expr, RefExpr) and isinstance(expr.node, Var) and expr.node.is_final:
787-
final_value = expr.node.final_value
788-
if final_value is not None:
789-
return str(final_value)
783+
elif isinstance(folded := constant_fold_expr(builder, expr), str):
784+
return folded
790785
return None
791786

792787
for i in range(len(exprs) - 1):

0 commit comments

Comments
 (0)