MCPcopy Index your code
hub / github.com/RustPython/RustPython / derive_and_copy_attributes

Function derive_and_copy_attributes

crates/vm/src/exception_group.rs:444–482  ·  view source on GitHub ↗
(
        orig: &Py<PyBaseException>,
        excs: Vec<PyObjectRef>,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

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}

Callers 2

subgroupMethod · 0.85
splitMethod · 0.85

Calls 12

is_base_exception_groupFunction · 0.85
new_listMethod · 0.80
__traceback__Method · 0.80
__context__Method · 0.80
__cause__Method · 0.80
to_vecMethod · 0.80
borrow_vecMethod · 0.80
ErrClass · 0.50
call_methodMethod · 0.45
as_objectMethod · 0.45
set_attrMethod · 0.45
get_attrMethod · 0.45

Tested by

no test coverage detected