Add object protocol correspoinding to PyObject_GetAIter (#5090)

This commit is contained in:
Dan Näsman authored and GitHub committed 2023-10-16 10:39:29 -07:00
1 parent 9241e2e5d5
commit 4e6172b99d
2 files changed
+10 -8

No files matched your search

+9 -2
View File
@@ -3,8 +3,8 @@
use crate::{
builtins::{
pystr::AsPyStr, PyBytes, PyDict, PyDictRef, PyGenericAlias, PyInt, PyList, PyStr, PyStrRef,
PyTuple, PyTupleRef, PyType, PyTypeRef,
pystr::AsPyStr, PyAsyncGen, PyBytes, PyDict, PyDictRef, PyGenericAlias, PyInt, PyList,
PyStr, PyStrRef, PyTuple, PyTupleRef, PyType, PyTypeRef,
},
bytesinner::ByteInnerNewOptions,
common::{hash::PyHash, str::to_ascii},
@@ -92,6 +92,13 @@ impl PyObject {
}
// PyObject *PyObject_GetAIter(PyObject *o)
pub fn get_aiter(&self, vm: &VirtualMachine) -> PyResult {
if self.payload_is::<PyAsyncGen>() {
vm.call_special_method(self, identifier!(vm, __aiter__), ())
} else {
Err(vm.new_type_error("wrong argument type".to_owned()))
}
}
pub fn has_attr<'a>(&self, attr_name: impl AsPyStr<'a>, vm: &VirtualMachine) -> PyResult<bool> {
self.get_attr(attr_name, vm).map(|o| !vm.is_none(&o))
+1 -6
View File
@@ -9,7 +9,6 @@ pub use builtins::{ascii, print, reversed};
mod builtins {
use crate::{
builtins::{
asyncgenerator::PyAsyncGen,
enumerate::PyReverseSequenceIterator,
function::{PyCellRef, PyFunction},
int::PyIntRef,
@@ -459,11 +458,7 @@ mod builtins {
#[pyfunction]
fn aiter(iter_target: PyObjectRef, vm: &VirtualMachine) -> PyResult {
if iter_target.payload_is::<PyAsyncGen>() {
vm.call_special_method(&iter_target, identifier!(vm, __aiter__), ())
} else {
Err(vm.new_type_error("wrong argument type".to_owned()))
}
iter_target.get_aiter(vm)
}
#[pyfunction]