Skip to content

Commit 1c41ab7

Browse files
committed
[mypyc] feat: support constant folding in translate_str_format
1 parent 053c054 commit 1c41ab7

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

mypyc/irbuild/specialize.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,10 +718,9 @@ def translate_dict_setdefault(builder: IRBuilder, expr: CallExpr, callee: RefExp
718718
def translate_str_format(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Value | None:
719719
if (
720720
isinstance(callee, MemberExpr)
721-
and isinstance(callee.expr, StrExpr)
721+
and isinstance(format_str := constant_fold_expr(builder, callee.expr), str)
722722
and expr.arg_kinds.count(ARG_POS) == len(expr.arg_kinds)
723723
):
724-
format_str = callee.expr.value
725724
tokens = tokenizer_format_call(format_str)
726725
if tokens is None:
727726
return None

0 commit comments

Comments
 (0)