MCPcopy Index your code
hub / github.com/RustPython/RustPython / anext

Function anext

crates/vm/src/stdlib/builtins.rs:787–811  ·  view source on GitHub ↗
(
        aiter: PyObjectRef,
        default_value: OptionalArg<PyObjectRef>,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

785
786 #[pyfunction]
787 fn anext(
788 aiter: PyObjectRef,
789 default_value: OptionalArg<PyObjectRef>,
790 vm: &VirtualMachine,
791 ) -> PyResult {
792 use crate::builtins::asyncgenerator::PyAnextAwaitable;
793
794 // Check if object is an async iterator (has __anext__ method)
795 if !aiter.class().has_attr(identifier!(vm, __anext__)) {
796 return Err(vm.new_type_error(format!(
797 "'{}' object is not an async iterator",
798 aiter.class().name()
799 )));
800 }
801
802 let awaitable = vm.call_method(&aiter, "__anext__", ())?;
803
804 if let OptionalArg::Present(default) = default_value {
805 Ok(PyAnextAwaitable::new(awaitable, default)
806 .into_ref(&vm.ctx)
807 .into())
808 } else {
809 Ok(awaitable)
810 }
811 }
812
813 #[pyfunction]
814 fn len(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<usize> {

Callers 15

__aenter__Method · 0.85
__aexit__Method · 0.85
genMethod · 0.85
consumeMethod · 0.85
test_2Method · 0.85
test_sendMethod · 0.85
test_throwMethod · 0.85
call_with_kwargMethod · 0.85
bad_awaitableMethod · 0.85

Calls 6

newFunction · 0.85
ErrClass · 0.50
has_attrMethod · 0.45
classMethod · 0.45
call_methodMethod · 0.45
into_refMethod · 0.45

Tested by 15

genMethod · 0.68
consumeMethod · 0.68
test_2Method · 0.68
test_sendMethod · 0.68
test_throwMethod · 0.68
call_with_kwargMethod · 0.68
bad_awaitableMethod · 0.68
do_testMethod · 0.68