mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
add PyIter_Check before using iternext
As [cpython 3.8 implementation](https://github.com/python/cpython/blob/main/Python/bltinmodule.c#L1448), add `PyIter_Check` and its error message. Signed-off-by: snowapril <sinjihng@gmail.com>
This commit is contained in:
@@ -513,6 +513,13 @@ mod builtins {
|
||||
default_value: OptionalArg<PyObjectRef>,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult {
|
||||
if !PyIter::check(&iterator) {
|
||||
return Err(vm.new_type_error(format!(
|
||||
"{} object is not an iterator",
|
||||
iterator.class().name()
|
||||
)));
|
||||
}
|
||||
|
||||
PyIter::new(iterator).next(vm).or_else(|err| {
|
||||
if err.isinstance(&vm.ctx.exceptions.stop_iteration) {
|
||||
default_value.ok_or(err)
|
||||
|
||||
Reference in New Issue
Block a user