(
orig: &Py<PyBaseException>,
excs: Vec<PyObjectRef>,
vm: &VirtualMachine,
)
| 442 | } |
| 443 | |
| 444 | fn derive_and_copy_attributes( |
| 445 | orig: &Py<PyBaseException>, |
| 446 | excs: Vec<PyObjectRef>, |
| 447 | vm: &VirtualMachine, |
| 448 | ) -> PyResult<PyObjectRef> { |
| 449 | // Call derive method to create new group |
| 450 | let excs_seq = vm.ctx.new_list(excs); |
| 451 | let new_group = vm.call_method(orig.as_object(), "derive", (excs_seq,))?; |
| 452 | |
| 453 | // Verify derive returned a BaseExceptionGroup |
| 454 | if !is_base_exception_group(&new_group, vm) { |
| 455 | return Err(vm.new_type_error("derive must return an instance of BaseExceptionGroup")); |
| 456 | } |
| 457 | |
| 458 | // Copy traceback |
| 459 | if let Some(tb) = orig.__traceback__() { |
| 460 | new_group.set_attr("__traceback__", tb, vm)?; |
| 461 | } |
| 462 | |
| 463 | // Copy context |
| 464 | if let Some(ctx) = orig.__context__() { |
| 465 | new_group.set_attr("__context__", ctx, vm)?; |
| 466 | } |
| 467 | |
| 468 | // Copy cause |
| 469 | if let Some(cause) = orig.__cause__() { |
| 470 | new_group.set_attr("__cause__", cause, vm)?; |
| 471 | } |
| 472 | |
| 473 | // Copy notes (if present) - make a copy of the list |
| 474 | if let Ok(notes) = orig.as_object().get_attr("__notes__", vm) |
| 475 | && let Some(notes_list) = notes.downcast_ref::<PyList>() |
| 476 | { |
| 477 | let notes_copy = vm.ctx.new_list(notes_list.borrow_vec().to_vec()); |
| 478 | new_group.set_attr("__notes__", notes_copy, vm)?; |
| 479 | } |
| 480 | |
| 481 | Ok(new_group) |
| 482 | } |
| 483 | } |
no test coverage detected