Skip to content

Commit b25479a

Browse files
morealclaude
andcommitted
Add CO_ITERABLE_COROUTINE flag and fix types tests
- Add ITERABLE_COROUTINE (0x0100) to CodeFlags in bytecode.rs - Update frame.rs to check for both COROUTINE and ITERABLE_COROUTINE flags when validating 'yield from' on coroutine objects - Remove False and workaround in types.coroutine() now that the flag is supported - Remove @unittest.expectedFailure from test_async_def and test_genfunc Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 16e26de commit b25479a

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

Lib/test/test_types.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,7 +2174,6 @@ def foo():
21742174
foo = types.coroutine(foo)
21752175
self.assertIs(aw, foo())
21762176

2177-
@unittest.expectedFailure # TODO: RUSTPYTHON
21782177
def test_async_def(self):
21792178
# Test that types.coroutine passes 'async def' coroutines
21802179
# without modification
@@ -2431,7 +2430,6 @@ def foo():
24312430
foo = types.coroutine(foo)
24322431
self.assertIs(foo(), gencoro)
24332432

2434-
@unittest.expectedFailure # TODO: RUSTPYTHON
24352433
def test_genfunc(self):
24362434
def gen(): yield
24372435
self.assertIs(types.coroutine(gen), gen)

Lib/types.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,7 @@ def coroutine(func):
292292
if not callable(func):
293293
raise TypeError('types.coroutine() expects a callable')
294294

295-
# XXX RUSTPYTHON TODO: iterable coroutine
296-
if (False and func.__class__ is FunctionType and
295+
if (func.__class__ is FunctionType and
297296
getattr(func, '__code__', None).__class__ is CodeType):
298297

299298
co_flags = func.__code__.co_flags

crates/compiler-core/src/bytecode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ bitflags! {
297297
const VARKEYWORDS = 0x0008;
298298
const GENERATOR = 0x0020;
299299
const COROUTINE = 0x0080;
300+
const ITERABLE_COROUTINE = 0x0100;
300301
/// If a code object represents a function and has a docstring,
301302
/// this bit is set and the first item in co_consts is the docstring.
302303
const HAS_DOCSTRING = 0x4000000;

crates/vm/src/frame.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,9 @@ impl ExecutingFrame<'_> {
10511051
let iterable = self.pop_value();
10521052
let iter = if iterable.class().is(vm.ctx.types.coroutine_type) {
10531053
// Coroutine requires CO_COROUTINE or CO_ITERABLE_COROUTINE flag
1054-
if !self.code.flags.intersects(bytecode::CodeFlags::COROUTINE) {
1054+
if !self.code.flags.intersects(
1055+
bytecode::CodeFlags::COROUTINE | bytecode::CodeFlags::ITERABLE_COROUTINE,
1056+
) {
10551057
return Err(vm.new_type_error(
10561058
"cannot 'yield from' a coroutine object in a non-coroutine generator"
10571059
.to_owned(),

0 commit comments

Comments
 (0)