Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Propagate errors while adding dict update sequence notes
  • Loading branch information
2jiyong committed Jul 29, 2026
commit a0adb664a8f9d95a3a3b0683aec68b76ec995a74
24 changes: 18 additions & 6 deletions crates/vm/src/builtins/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,23 @@ impl PyDict {
self.merge_object_with_override(other, false, vm)
}

fn add_update_sequence_note(exc: &PyBaseExceptionRef, index: usize, vm: &VirtualMachine) {
if exc.fast_isinstance(vm.ctx.exceptions.type_error) {
let note =
format!("Cannot convert dictionary update sequence element #{index} to a sequence");
let _ = vm.call_method(exc.as_object(), "add_note", (vm.ctx.new_str(note),));
fn add_update_sequence_note(
exc: PyBaseExceptionRef,
index: usize,
vm: &VirtualMachine,
) -> PyBaseExceptionRef {
if !exc.fast_isinstance(vm.ctx.exceptions.type_error) {
return exc;
}

let note =
format!("Cannot convert dictionary update sequence element #{index} to a sequence");
match vm.call_method(exc.as_object(), "add_note", (vm.ctx.new_str(note),)) {
Ok(_) => exc,
Err(note_err) => {
note_err.set___context__(Some(exc));
note_err
}
}
}

Expand Down Expand Up @@ -240,7 +252,7 @@ impl PyDict {
.into_iter::<PyObjectRef>(vm)?
.collect::<PyResult<Vec<_>>>()
})()
.inspect_err(|exc| Self::add_update_sequence_note(exc, index, vm))?;
.map_err(|exc| Self::add_update_sequence_note(exc, index, vm))?;

Self::update_sequence_pair_from_slice(&elements, index, vm)
}
Expand Down