| 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> { |