Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Call __next__ directly if possible in await
  • Loading branch information
JukkaL committed Jul 4, 2025
commit e1282a75ff655fc6c96e3b6ce1c4b20fe9da2466
10 changes: 9 additions & 1 deletion mypyc/irbuild/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
)
from mypyc.common import TEMP_ATTR_NAME
from mypyc.ir.ops import (
ERR_NEVER,
NAMESPACE_MODULE,
NO_TRACEBACK_LINE_NO,
Assign,
Expand Down Expand Up @@ -944,7 +945,14 @@ def emit_yield_from_or_await(
iter_reg = builder.maybe_spill_assignable(iter_val)

stop_block, main_block, done_block = BasicBlock(), BasicBlock(), BasicBlock()
_y_init = builder.call_c(next_raw_op, [builder.read(iter_reg)], line)

if isinstance(iter_reg.type, RInstance) and iter_reg.type.class_ir.has_method("__next__"):
m = MethodCall(builder.read(iter_reg), "__next__", [], line)
m.error_kind = ERR_NEVER
_y_init = builder.add(m)
else:
_y_init = builder.call_c(next_raw_op, [builder.read(iter_reg)], line)

builder.add(Branch(_y_init, stop_block, main_block, Branch.IS_ERROR))

# Try extracting a return value from a StopIteration and return it.
Expand Down