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

Function is_exception_from_orig

crates/vm/src/exceptions.rs:2893–2908  ·  view source on GitHub ↗

Check if an exception came from the original group (for reraise detection). Instead of comparing metadata (which can be modified when caught), we compare leaf exception object IDs. split() preserves leaf exception identity.

(exc: &PyObjectRef, orig: &PyObjectRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

2891/// Instead of comparing metadata (which can be modified when caught), we compare
2892/// leaf exception object IDs. split() preserves leaf exception identity.
2893fn is_exception_from_orig(exc: &PyObjectRef, orig: &PyObjectRef, vm: &VirtualMachine) -> bool {
2894 // Collect leaf exception IDs from exc
2895 let mut exc_leaf_ids = HashSet::new();
2896 collect_exception_group_leaf_ids(exc, &mut exc_leaf_ids, vm);
2897
2898 if exc_leaf_ids.is_empty() {
2899 return false;
2900 }
2901
2902 // Collect leaf exception IDs from orig
2903 let mut orig_leaf_ids = HashSet::new();
2904 collect_exception_group_leaf_ids(orig, &mut orig_leaf_ids, vm);
2905
2906 // If ALL of exc's leaves are in orig's leaves, it's a reraise
2907 exc_leaf_ids.iter().all(|id| orig_leaf_ids.contains(id))
2908}
2909
2910/// Collect all leaf exception IDs from an exception (group).
2911fn collect_exception_group_leaf_ids(

Callers 1

prep_reraise_starFunction · 0.85

Calls 6

newFunction · 0.85
allMethod · 0.80
is_emptyMethod · 0.45
iterMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected