Skip to content

Commit 9939e51

Browse files
committed
[mypyc] feat: support constant folding in translate_ord
1 parent 053c054 commit 9939e51

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

mypyc/irbuild/specialize.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,8 +1060,9 @@ def translate_ord(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Value
10601060
if len(expr.args) != 1 or expr.arg_kinds[0] != ARG_POS:
10611061
return None
10621062
arg = expr.args[0]
1063-
if isinstance(arg, (StrExpr, BytesExpr)) and len(arg.value) == 1:
1064-
return Integer(ord(arg.value))
1063+
folded_arg = constant_fold_expr(builder, arg)
1064+
if isinstance(folded_arg, (str, bytes)) and len(folded_arg) == 1:
1065+
return Integer(ord(folded_arg))
10651066
return None
10661067

10671068

0 commit comments

Comments
 (0)