Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions mypyc/irbuild/specialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from mypy.nodes import (
ARG_NAMED,
ARG_POS,
BytesExpr,
CallExpr,
DictExpr,
Expression,
Expand Down Expand Up @@ -78,6 +77,7 @@
uint8_rprimitive,
)
from mypyc.irbuild.builder import IRBuilder
from mypyc.irbuild.constant_fold import constant_fold_expr
from mypyc.irbuild.for_helpers import (
comprehension_helper,
sequence_from_generator_preallocate_helper,
Expand Down Expand Up @@ -1059,9 +1059,9 @@ def translate_float(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Valu
def translate_ord(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Value | None:
if len(expr.args) != 1 or expr.arg_kinds[0] != ARG_POS:
return None
arg = expr.args[0]
if isinstance(arg, (StrExpr, BytesExpr)) and len(arg.value) == 1:
return Integer(ord(arg.value))
arg = constant_fold_expr(builder, expr.args[0])
if isinstance(arg, (str, bytes)) and len(arg) == 1:
return Integer(ord(arg))
return None


Expand Down