GeezerVison is showing github.com — Add CO_ITERABLE_COROUTINE flag and fix types tests · RustPython/RustPython@38ff638
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: Lib/test/test_types.py -2Lines changed: 0 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2174,7 +2174,6 @@ def foo(): |
2174 | 2174 | foo = types.coroutine(foo) |
2175 | 2175 | self.assertIs(aw, foo()) |
2176 | 2176 |
|
2177 | | - @unittest.expectedFailure # TODO: RUSTPYTHON |
2178 | 2177 | def test_async_def(self): |
2179 | 2178 | # Test that types.coroutine passes 'async def' coroutines |
2180 | 2179 | # without modification |
@@ -2431,7 +2430,6 @@ def foo(): |
2431 | 2430 | foo = types.coroutine(foo) |
2432 | 2431 | self.assertIs(foo(), gencoro) |
2433 | 2432 |
|
2434 | | - @unittest.expectedFailure # TODO: RUSTPYTHON |
2435 | 2433 | def test_genfunc(self): |
2436 | 2434 | def gen(): yield |
2437 | 2435 | self.assertIs(types.coroutine(gen), gen) |
|
Collapse file
Copy file name to clipboardExpand all lines: Lib/types.py +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -292,8 +292,7 @@ def coroutine(func): |
292 | 292 | if not callable(func): |
293 | 293 | raise TypeError('types.coroutine() expects a callable') |
294 | 294 |
|
295 | | - # XXX RUSTPYTHON TODO: iterable coroutine |
296 | | - if (False and func.__class__ is FunctionType and |
| 295 | + if (func.__class__ is FunctionType and |
297 | 296 | getattr(func, '__code__', None).__class__ is CodeType): |
298 | 297 |
|
299 | 298 | co_flags = func.__code__.co_flags |
|
Collapse file
Copy file name to clipboardExpand all lines: crates/compiler-core/src/bytecode.rs +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -297,6 +297,7 @@ bitflags! { |
297 | 297 | const VARKEYWORDS = 0x0008; |
298 | 298 | const GENERATOR = 0x0020; |
299 | 299 | const COROUTINE = 0x0080; |
| 300 | + const ITERABLE_COROUTINE = 0x0100; |
300 | 301 | /// If a code object represents a function and has a docstring, |
301 | 302 | /// this bit is set and the first item in co_consts is the docstring. |
302 | 303 | const HAS_DOCSTRING = 0x4000000; |
|
Collapse file
Copy file name to clipboardExpand all lines: crates/vm/src/frame.rs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1051,7 +1051,7 @@ impl ExecutingFrame<'_> { |
1051 | 1051 | let iterable = self.pop_value(); |
1052 | 1052 | let iter = if iterable.class().is(vm.ctx.types.coroutine_type) { |
1053 | 1053 | // Coroutine requires CO_COROUTINE or CO_ITERABLE_COROUTINE flag |
1054 | | - if !self.code.flags.intersects(bytecode::CodeFlags::COROUTINE) { |
| 1054 | + if !self.code.flags.intersects(bytecode::CodeFlags::COROUTINE | bytecode::CodeFlags::ITERABLE_COROUTINE) { |
1055 | 1055 | return Err(vm.new_type_error( |
1056 | 1056 | "cannot 'yield from' a coroutine object in a non-coroutine generator" |
1057 | 1057 | .to_owned(), |
|