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

Function get_filter

crates/vm/src/warn.rs:262–299  ·  view source on GitHub ↗

Search the global filters list for a matching action. TODO: split into filter_search() + get_filter() and support context-aware filters (get_warnings_context_filters).

(
    category: PyObjectRef,
    text: PyObjectRef,
    lineno: usize,
    module: PyObjectRef,
    vm: &VirtualMachine,
)

Source from the content-addressed store, hash-verified

260// TODO: split into filter_search() + get_filter() and support
261// context-aware filters (get_warnings_context_filters).
262fn get_filter(
263 category: PyObjectRef,
264 text: PyObjectRef,
265 lineno: usize,
266 module: PyObjectRef,
267 vm: &VirtualMachine,
268) -> PyResult {
269 let filters = get_warnings_filters(vm)?;
270
271 // filters could change while we are iterating over it.
272 // Re-check list length each iteration (matches C behavior).
273 let mut i = 0;
274 while i < filters.borrow_vec().len() {
275 let Some(tmp_item) = filters.borrow_vec().get(i).cloned() else {
276 break;
277 };
278 let tmp_item = PyTupleRef::try_from_object(vm, tmp_item)
279 .ok()
280 .filter(|t| t.len() == 5)
281 .ok_or_else(|| {
282 vm.new_value_error(format!("_warnings.filters item {i} isn't a 5-tuple"))
283 })?;
284
285 /* action, msg, cat, mod, ln = item */
286 let action = &tmp_item[0];
287 let good_msg = check_matched(&tmp_item[1], &text, vm)?;
288 let is_subclass = category.is_subclass(&tmp_item[2], vm)?;
289 let good_mod = check_matched(&tmp_item[3], &module, vm)?;
290 let ln: usize = tmp_item[4].try_int(vm).map_or(0, |v| v.as_u32_mask() as _);
291
292 if good_msg && is_subclass && good_mod && (ln == 0 || lineno == ln) {
293 return Ok(action.to_owned());
294 }
295 i += 1;
296 }
297
298 get_default_action(vm)
299}
300
301pub fn warn(
302 message: PyObjectRef,

Callers 1

warn_explicitFunction · 0.85

Calls 13

get_warnings_filtersFunction · 0.85
check_matchedFunction · 0.85
get_default_actionFunction · 0.85
borrow_vecMethod · 0.80
ok_or_elseMethod · 0.80
okMethod · 0.80
is_subclassMethod · 0.80
try_intMethod · 0.80
as_u32_maskMethod · 0.80
lenMethod · 0.45
getMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected