more useful vm.new_stop_iteration

This commit is contained in:
Jeong YunWon
2021-10-03 03:36:08 +09:00
parent 32770249eb
commit a8a3fa653b
3 changed files with 11 additions and 13 deletions

View File

@@ -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
}

View File

@@ -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)),
}
}
}

View File

@@ -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]