mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
more useful vm.new_stop_iteration
This commit is contained in:
@@ -155,10 +155,7 @@ impl PyAsyncGenWrappedValue {
|
||||
match_class!(match val {
|
||||
val @ Self => {
|
||||
ag.running_async.store(false);
|
||||
Err(vm.new_exception(
|
||||
vm.ctx.exceptions.stop_iteration.clone(),
|
||||
vec![val.0.clone()],
|
||||
))
|
||||
Err(vm.new_stop_iteration(Some(val.0.clone())))
|
||||
}
|
||||
val => Ok(val),
|
||||
})
|
||||
@@ -307,7 +304,7 @@ impl PyAsyncGenAThrow {
|
||||
}
|
||||
if self.ag.inner.closed() {
|
||||
self.state.store(AwaitableState::Closed);
|
||||
return Err(vm.new_exception_empty(vm.ctx.exceptions.stop_iteration.clone()));
|
||||
return Err(vm.new_stop_iteration(None));
|
||||
}
|
||||
if !vm.is_none(&val) {
|
||||
return Err(vm.new_runtime_error(
|
||||
@@ -398,7 +395,7 @@ impl PyAsyncGenAThrow {
|
||||
&& (exc.isinstance(&vm.ctx.exceptions.stop_async_iteration)
|
||||
|| exc.isinstance(&vm.ctx.exceptions.generator_exit))
|
||||
{
|
||||
vm.new_exception_empty(vm.ctx.exceptions.stop_iteration.clone())
|
||||
vm.new_stop_iteration(None)
|
||||
} else {
|
||||
exc
|
||||
}
|
||||
|
||||
@@ -166,10 +166,7 @@ impl IntoPyResult for PyIterReturn {
|
||||
fn into_pyresult(self, vm: &VirtualMachine) -> PyResult {
|
||||
match self {
|
||||
Self::Return(obj) => Ok(obj),
|
||||
Self::StopIteration(v) => Err({
|
||||
let args = if let Some(v) = v { vec![v] } else { Vec::new() };
|
||||
vm.new_exception(vm.ctx.exceptions.stop_iteration.clone(), args)
|
||||
}),
|
||||
Self::StopIteration(v) => Err(vm.new_stop_iteration(v)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
10
vm/src/vm.rs
10
vm/src/vm.rs
@@ -800,9 +800,13 @@ impl VirtualMachine {
|
||||
self.new_exception_msg(memory_error_type, msg)
|
||||
}
|
||||
|
||||
pub fn new_stop_iteration(&self) -> PyBaseExceptionRef {
|
||||
let stop_iteration_type = self.ctx.exceptions.stop_iteration.clone();
|
||||
self.new_exception_empty(stop_iteration_type)
|
||||
pub fn new_stop_iteration(&self, value: Option<PyObjectRef>) -> PyBaseExceptionRef {
|
||||
let args = if let Some(value) = value {
|
||||
vec![value]
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
self.new_exception(self.ctx.exceptions.stop_iteration.clone(), args)
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
|
||||
Reference in New Issue
Block a user