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

Method subgroup

crates/vm/src/exception_group.rs:81–125  ·  view source on GitHub ↗
(
            zelf: PyRef<PyBaseException>,
            condition: PyObjectRef,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

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(

Callers

nothing calls this directly

Calls 13

get_condition_matcherFunction · 0.85
get_exceptions_tupleFunction · 0.85
newFunction · 0.85
is_base_exception_groupFunction · 0.85
isMethod · 0.80
noneMethod · 0.80
cloneMethod · 0.45
checkMethod · 0.45
call_methodMethod · 0.45
is_noneMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected