Skip to content

Commit 2a1eb1c

Browse files
[mypyc] fix: inappropriate Nones in f-strings
if a variable is Final but the value is not yet known at compile-time, and that variable is used as an input to an f-string, the f-string will incorrectly contain "None"
1 parent 8412d1d commit 2a1eb1c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

mypyc/irbuild/specialize.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,9 @@ def get_literal_str(expr: Expression) -> str | None:
719719
if isinstance(expr, StrExpr):
720720
return expr.value
721721
elif isinstance(expr, RefExpr) and isinstance(expr.node, Var) and expr.node.is_final:
722-
return str(expr.node.final_value)
722+
final_value = expr.node.final_value
723+
if final_value is not None:
724+
return str(final_value)
723725
return None
724726

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

0 commit comments

Comments
 (0)