(
zelf: PyRef<PyBaseException>,
condition: PyObjectRef,
vm: &VirtualMachine,
)
| 79 | |
| 80 | #[pymethod] |
| 81 | fn subgroup( |
| 82 | zelf: PyRef<PyBaseException>, |
| 83 | condition: PyObjectRef, |
| 84 | vm: &VirtualMachine, |
| 85 | ) -> PyResult { |
| 86 | let matcher = get_condition_matcher(&condition, vm)?; |
| 87 | |
| 88 | // If self matches the condition entirely, return self |
| 89 | let zelf_obj: PyObjectRef = zelf.clone().into(); |
| 90 | if matcher.check(&zelf_obj, vm)? { |
| 91 | return Ok(zelf_obj); |
| 92 | } |
| 93 | |
| 94 | let exceptions = get_exceptions_tuple(&zelf, vm)?; |
| 95 | let mut matching: Vec<PyObjectRef> = Vec::new(); |
| 96 | let mut modified = false; |
| 97 | |
| 98 | for exc in exceptions { |
| 99 | if is_base_exception_group(&exc, vm) { |
| 100 | // Recursive call for nested groups |
| 101 | let subgroup_result = vm.call_method(&exc, "subgroup", (condition.clone(),))?; |
| 102 | if !vm.is_none(&subgroup_result) { |
| 103 | matching.push(subgroup_result.clone()); |
| 104 | } |
| 105 | if !subgroup_result.is(&exc) { |
| 106 | modified = true; |
| 107 | } |
| 108 | } else if matcher.check(&exc, vm)? { |
| 109 | matching.push(exc); |
| 110 | } else { |
| 111 | modified = true; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | if !modified { |
| 116 | return Ok(zelf.clone().into()); |
| 117 | } |
| 118 | |
| 119 | if matching.is_empty() { |
| 120 | return Ok(vm.ctx.none()); |
| 121 | } |
| 122 | |
| 123 | // Create new group with matching exceptions and copy metadata |
| 124 | derive_and_copy_attributes(&zelf, matching, vm) |
| 125 | } |
| 126 | |
| 127 | #[pymethod] |
| 128 | fn split( |
nothing calls this directly
no test coverage detected