FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

implement aiter by sum12 · Pull Request #3646 · RustPython/RustPython · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .rs  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 0 additions & 4 deletions Lib/test/test_asyncgen.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions vm/src/stdlib/builtins.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod builtins {
use crate::compile;
use crate::{
builtins::{
asyncgenerator::PyAsyncGen,
enumerate::PyReverseSequenceIterator,
function::{PyCellRef, PyFunctionRef},
int::PyIntRef,
Expand Down Expand Up @@ -426,6 +427,15 @@ mod builtins {
}
}

#[pyfunction]
fn aiter(iter_target: PyObjectRef, vm: &VirtualMachine) -> PyResult {
if iter_target.payload_is::<PyAsyncGen>() {
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<usize> {
obj.length(vm)
Expand Down

Back | FazBrowse Home | New Git URL