Skip to content

Commit f26c0ba

Browse files
authored
Merge pull request RustPython#3646 from sum12/aiter
implement aiter
2 parents 9a8e385 + 5fdf62a commit f26c0ba

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Lib/test/test_asyncgen.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,6 @@ async def consume():
543543
self.loop.run_until_complete(consume())
544544
self.assertEqual(results, [1, 2])
545545

546-
# TODO: RUSTPYTHON, NameError: name 'aiter' is not defined
547-
@unittest.expectedFailure
548546
def test_aiter_idempotent(self):
549547
async def gen():
550548
yield 1
@@ -766,8 +764,6 @@ def run_test(test):
766764
run_test(test5)
767765
run_test(test6)
768766

769-
# TODO: RUSTPYTHON, NameError: name 'aiter' is not defined
770-
@unittest.expectedFailure
771767
def test_aiter_bad_args(self):
772768
async def gen():
773769
yield 1

vm/src/stdlib/builtins.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ mod builtins {
1212
use crate::compile;
1313
use crate::{
1414
builtins::{
15+
asyncgenerator::PyAsyncGen,
1516
enumerate::PyReverseSequenceIterator,
1617
function::{PyCellRef, PyFunctionRef},
1718
int::PyIntRef,
@@ -426,6 +427,15 @@ mod builtins {
426427
}
427428
}
428429

430+
#[pyfunction]
431+
fn aiter(iter_target: PyObjectRef, vm: &VirtualMachine) -> PyResult {
432+
if iter_target.payload_is::<PyAsyncGen>() {
433+
vm.call_special_method(iter_target, "__aiter__", ())
434+
} else {
435+
Err(vm.new_type_error("wrong argument type".to_owned()))
436+
}
437+
}
438+
429439
#[pyfunction]
430440
fn len(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<usize> {
431441
obj.length(vm)

0 commit comments

Comments
 (0)