Skip to content

Commit 1b8841b

Browse files
[mypyc] feat: support constant folding in translate_ord [1/1] (#19968)
This PR adds support for constant folding inside of `translate_ord` --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent a62f273 commit 1b8841b

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

mypyc/irbuild/specialize.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from mypy.nodes import (
2020
ARG_NAMED,
2121
ARG_POS,
22-
BytesExpr,
2322
CallExpr,
2423
DictExpr,
2524
Expression,
@@ -1057,9 +1056,9 @@ def translate_float(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Valu
10571056
def translate_ord(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Value | None:
10581057
if len(expr.args) != 1 or expr.arg_kinds[0] != ARG_POS:
10591058
return None
1060-
arg = expr.args[0]
1061-
if isinstance(arg, (StrExpr, BytesExpr)) and len(arg.value) == 1:
1062-
return Integer(ord(arg.value))
1059+
arg = constant_fold_expr(builder, expr.args[0])
1060+
if isinstance(arg, (str, bytes)) and len(arg) == 1:
1061+
return Integer(ord(arg))
10631062
return None
10641063

10651064

0 commit comments

Comments
 (0)