PyIter::iter

This commit is contained in:
Jeong YunWon
2021-10-04 00:34:52 +09:00
parent d1e9ac85d8
commit d0615a4ea3
2 changed files with 13 additions and 6 deletions

View File

@@ -51,14 +51,11 @@ impl<T> ArgIterable<T> {
/// This operation may fail if an exception is raised while invoking the
/// `__iter__` method of the iterable object.
pub fn iter<'a>(&self, vm: &'a VirtualMachine) -> PyResult<PyIterIter<'a, T>> {
let iter_obj = match self.iterfn {
let iter = PyIter::new(match self.iterfn {
Some(f) => f(self.iterable.clone(), vm)?,
None => PySequenceIterator::new(self.iterable.clone()).into_object(vm),
};
let length_hint = vm.length_hint(iter_obj.clone())?;
Ok(PyIterIter::new(vm, PyIter::new(iter_obj), length_hint))
});
iter.iter(vm)
}
}

View File

@@ -50,6 +50,16 @@ where
};
iternext(self.0.borrow(), vm)
}
pub fn iter<'a, U>(&self, vm: &'a VirtualMachine) -> PyResult<PyIterIter<'a, U>> {
let obj = self.as_object();
let length_hint = vm.length_hint(obj.clone())?;
Ok(PyIterIter::new(
vm,
PyIter::<PyObjectRef>::new(obj.clone()),
length_hint,
))
}
}
impl<T> Borrow<PyObjectRef> for PyIter<T>