Project orig onto keep list, preserving nested structure. Returns an exception group containing only the exceptions from orig that are also in the keep list.
(
orig: &PyObjectRef,
keep: &[PyObjectRef],
vm: &VirtualMachine,
)
| 2937 | /// Returns an exception group containing only the exceptions from orig |
| 2938 | /// that are also in the keep list. |
| 2939 | fn exception_group_projection( |
| 2940 | orig: &PyObjectRef, |
| 2941 | keep: &[PyObjectRef], |
| 2942 | vm: &VirtualMachine, |
| 2943 | ) -> PyResult { |
| 2944 | if keep.is_empty() { |
| 2945 | return Ok(vm.ctx.none()); |
| 2946 | } |
| 2947 | |
| 2948 | // Collect all leaf IDs from keep list |
| 2949 | let mut leaf_ids = HashSet::new(); |
| 2950 | for e in keep { |
| 2951 | collect_exception_group_leaf_ids(e, &mut leaf_ids, vm); |
| 2952 | } |
| 2953 | |
| 2954 | // Split orig by matching leaf IDs, preserving structure |
| 2955 | split_by_leaf_ids(orig, &leaf_ids, vm) |
| 2956 | } |
| 2957 | |
| 2958 | /// Recursively split an exception (group) by leaf IDs. |
| 2959 | /// Returns the projection containing only matching leaves with preserved structure. |
no test coverage detected