Skip to content

Commit 2d9876a

Browse files
committed
Fix STOP_ITERATION monitoring: wrap value in StopIteration instance
fire_stop_iteration was passing the raw iterator return value to callbacks, but the STOP_ITERATION event callback signature expects a StopIteration exception instance. Wrap non-StopIteration values in a new StopIteration(value), matching PyMonitoring_FireStopIterationEvent. This fixes test_pdb_await_support where bdb's exception_callback received None instead of a StopIteration instance. Assisted-by: Claude
1 parent fddc73c commit 2d9876a

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

‎crates/vm/src/stdlib/sys/monitoring.rs‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,18 +1038,29 @@ pub(crate) fn fire_py_throw(
10381038
)
10391039
}
10401040

1041+
/// If `value` is already a `StopIteration`, pass it directly; otherwise wrap
1042+
/// it in a new `StopIteration(value)` — matching `PyMonitoring_FireStopIterationEvent`.
10411043
pub(crate) fn fire_stop_iteration(
10421044
vm: &VirtualMachine,
10431045
code: &Py<PyCode>,
10441046
offset: u32,
1045-
exception: &PyObjectRef,
1047+
value: &PyObjectRef,
10461048
) -> PyResult<()> {
1049+
let exc: PyObjectRef = if value.fast_isinstance(vm.ctx.exceptions.stop_iteration) {
1050+
value.clone()
1051+
} else {
1052+
vm.ctx
1053+
.exceptions
1054+
.stop_iteration
1055+
.as_object()
1056+
.call(vec![value.clone()], vm)?
1057+
};
10471058
fire(
10481059
vm,
10491060
EVENT_STOP_ITERATION,
10501061
code,
10511062
offset,
1052-
&[vm.ctx.new_int(offset).into(), exception.clone()],
1063+
&[vm.ctx.new_int(offset).into(), exc],
10531064
)
10541065
}
10551066

0 commit comments

Comments
 (0)