Skip to content

Commit f93b741

Browse files
committed
more useful vm.new_stop_iteration
1 parent e4aea92 commit f93b741

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

vm/src/builtins/asyncgenerator.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,7 @@ impl PyAsyncGenWrappedValue {
155155
match_class!(match val {
156156
val @ Self => {
157157
ag.running_async.store(false);
158-
Err(vm.new_exception(
159-
vm.ctx.exceptions.stop_iteration.clone(),
160-
vec![val.0.clone()],
161-
))
158+
Err(vm.new_stop_iteration(Some(val.0.clone())))
162159
}
163160
val => Ok(val),
164161
})
@@ -307,7 +304,7 @@ impl PyAsyncGenAThrow {
307304
}
308305
if self.ag.inner.closed() {
309306
self.state.store(AwaitableState::Closed);
310-
return Err(vm.new_exception_empty(vm.ctx.exceptions.stop_iteration.clone()));
307+
return Err(vm.new_stop_iteration(None));
311308
}
312309
if !vm.is_none(&val) {
313310
return Err(vm.new_runtime_error(
@@ -398,7 +395,7 @@ impl PyAsyncGenAThrow {
398395
&& (exc.isinstance(&vm.ctx.exceptions.stop_async_iteration)
399396
|| exc.isinstance(&vm.ctx.exceptions.generator_exit))
400397
{
401-
vm.new_exception_empty(vm.ctx.exceptions.stop_iteration.clone())
398+
vm.new_stop_iteration(None)
402399
} else {
403400
exc
404401
}

vm/src/protocol/iter.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,7 @@ impl IntoPyResult for PyIterReturn {
166166
fn into_pyresult(self, vm: &VirtualMachine) -> PyResult {
167167
match self {
168168
Self::Return(obj) => Ok(obj),
169-
Self::StopIteration(v) => Err({
170-
let args = if let Some(v) = v { vec![v] } else { Vec::new() };
171-
vm.new_exception(vm.ctx.exceptions.stop_iteration.clone(), args)
172-
}),
169+
Self::StopIteration(v) => Err(vm.new_stop_iteration(v)),
173170
}
174171
}
175172
}

vm/src/vm.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,9 +800,13 @@ impl VirtualMachine {
800800
self.new_exception_msg(memory_error_type, msg)
801801
}
802802

803-
pub fn new_stop_iteration(&self) -> PyBaseExceptionRef {
804-
let stop_iteration_type = self.ctx.exceptions.stop_iteration.clone();
805-
self.new_exception_empty(stop_iteration_type)
803+
pub fn new_stop_iteration(&self, value: Option<PyObjectRef>) -> PyBaseExceptionRef {
804+
let args = if let Some(value) = value {
805+
vec![value]
806+
} else {
807+
Vec::new()
808+
};
809+
self.new_exception(self.ctx.exceptions.stop_iteration.clone(), args)
806810
}
807811

808812
#[track_caller]

0 commit comments

Comments
 (0)