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
Handle CO_ITERABLE_COROUTINE flag in GetAwaitable instruction
Generators decorated with @types.coroutine have the CO_ITERABLE_COROUTINE
flag set, making them awaitable. The GetAwaitable instruction now properly
handles this case instead of only checking for __await__ method.

This fixes the "object generator can't be used in 'await' expression" error
that occurred with asyncio.sleep(0) which uses @types.coroutine decorated
__sleep0() generator internally.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
  • Loading branch information
moreal and claude committed Jan 22, 2026
commit be354cd3d86500a719205aa8a28ee45d70fa7f9a
17 changes: 17 additions & 0 deletions crates/vm/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,23 @@ impl ExecutingFrame<'_> {
);
}
awaited_obj
} else if let Some(generator) = awaited_obj.downcast_ref::<PyGenerator>() {
// Generator with CO_ITERABLE_COROUTINE flag can be awaited
// (e.g., generators decorated with @types.coroutine)
if generator
.as_coro()
.frame()
.code
.flags
.contains(bytecode::CodeFlags::ITERABLE_COROUTINE)
{
awaited_obj
} else {
return Err(vm.new_type_error(format!(
"object {} can't be used in 'await' expression",
awaited_obj.class().name(),
)));
}
} else {
let await_method = vm.get_method_or_type_error(
awaited_obj.clone(),
Expand Down