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

Function collect_exception_group_leaf_ids

crates/vm/src/exceptions.rs:2911–2934  ·  view source on GitHub ↗

Collect all leaf exception IDs from an exception (group).

(
    exc: &PyObjectRef,
    leaf_ids: &mut HashSet<usize>,
    vm: &VirtualMachine,
)

Source from the content-addressed store, hash-verified

2909
2910/// Collect all leaf exception IDs from an exception (group).
2911fn collect_exception_group_leaf_ids(
2912 exc: &PyObjectRef,
2913 leaf_ids: &mut HashSet<usize>,
2914 vm: &VirtualMachine,
2915) {
2916 if vm.is_none(exc) {
2917 return;
2918 }
2919
2920 // If not an exception group, it's a leaf - add its ID
2921 if !exc.fast_isinstance(vm.ctx.exceptions.base_exception_group) {
2922 leaf_ids.insert(exc.get_id());
2923 return;
2924 }
2925
2926 // Recurse into exception group's exceptions
2927 if let Ok(excs_attr) = exc.get_attr("exceptions", vm)
2928 && let Ok(tuple) = excs_attr.downcast::<PyTuple>()
2929 {
2930 for e in tuple.iter() {
2931 collect_exception_group_leaf_ids(e, leaf_ids, vm);
2932 }
2933 }
2934}
2935
2936/// Project orig onto keep list, preserving nested structure.
2937/// Returns an exception group containing only the exceptions from orig

Callers 2

is_exception_from_origFunction · 0.85

Calls 6

fast_isinstanceMethod · 0.80
is_noneMethod · 0.45
insertMethod · 0.45
get_idMethod · 0.45
get_attrMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected