diff --git a/Lib/test/test_asyncgen.py b/Lib/test/test_asyncgen.py index c8024d659f1..f6d05a61437 100644 --- a/Lib/test/test_asyncgen.py +++ b/Lib/test/test_asyncgen.py @@ -543,8 +543,6 @@ async def consume(): self.loop.run_until_complete(consume()) self.assertEqual(results, [1, 2]) - # TODO: RUSTPYTHON, NameError: name 'aiter' is not defined - @unittest.expectedFailure def test_aiter_idempotent(self): async def gen(): yield 1 @@ -766,8 +764,6 @@ def run_test(test): run_test(test5) run_test(test6) - # TODO: RUSTPYTHON, NameError: name 'aiter' is not defined - @unittest.expectedFailure def test_aiter_bad_args(self): async def gen(): yield 1 diff --git a/vm/src/stdlib/builtins.rs b/vm/src/stdlib/builtins.rs index c13a8299085..c1829d3dfda 100644 --- a/vm/src/stdlib/builtins.rs +++ b/vm/src/stdlib/builtins.rs @@ -12,6 +12,7 @@ mod builtins { use crate::compile; use crate::{ builtins::{ + asyncgenerator::PyAsyncGen, enumerate::PyReverseSequenceIterator, function::{PyCellRef, PyFunctionRef}, int::PyIntRef, @@ -426,6 +427,15 @@ mod builtins { } } + #[pyfunction] + fn aiter(iter_target: PyObjectRef, vm: &VirtualMachine) -> PyResult { + if iter_target.payload_is::() { + vm.call_special_method(iter_target, "__aiter__", ()) + } else { + Err(vm.new_type_error("wrong argument type".to_owned())) + } + } + #[pyfunction] fn len(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult { obj.length(vm)