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)
| 2891 | /// Instead of comparing metadata (which can be modified when caught), we compare |
| 2892 | /// leaf exception object IDs. split() preserves leaf exception identity. |
| 2893 | fn 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). |
| 2911 | fn collect_exception_group_leaf_ids( |
no test coverage detected