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

Function warn_explicit

crates/vm/src/warn.rs:335–453  ·  view source on GitHub ↗
(
    category: Option<PyTypeRef>,
    message: PyObjectRef,
    filename: PyStrRef,
    lineno: usize,
    module: Option<PyObjectRef>,
    registry: PyObjectRef,
    source_line: Option<PyObjectRef>

Source from the content-addressed store, hash-verified

333/// Core warning logic matching `warn_explicit()` in `_warnings.c`.
334#[allow(clippy::too_many_arguments)]
335pub(crate) fn warn_explicit(
336 category: Option<PyTypeRef>,
337 message: PyObjectRef,
338 filename: PyStrRef,
339 lineno: usize,
340 module: Option<PyObjectRef>,
341 registry: PyObjectRef,
342 source_line: Option<PyObjectRef>,
343 source: Option<PyObjectRef>,
344 vm: &VirtualMachine,
345) -> PyResult<()> {
346 // Normalize module. None → silent return (late-shutdown safety).
347 let module = module.unwrap_or_else(|| normalize_module(&filename, vm));
348 if vm.is_none(&module) {
349 return Ok(());
350 }
351
352 // Normalize message.
353 let is_warning = message.fast_isinstance(vm.ctx.exceptions.warning);
354 let (text, category, message) = if is_warning {
355 let text = message.str(vm)?;
356 let cat = message.class().to_owned();
357 (text, cat, message)
358 } else {
359 // For non-Warning messages, convert to string via str()
360 let text = message.str(vm)?;
361 let cat = category.unwrap_or_else(|| vm.ctx.exceptions.user_warning.to_owned());
362 let instance = cat.as_object().call((text.clone(),), vm)?;
363 (text, cat, instance)
364 };
365
366 let lineno_obj: PyObjectRef = vm.ctx.new_int(lineno).into();
367
368 // key = (text, category, lineno)
369 let key: PyObjectRef = PyTuple::new_ref(
370 vec![
371 text.clone().into(),
372 category.as_object().to_owned(),
373 lineno_obj.clone(),
374 ],
375 &vm.ctx,
376 )
377 .into();
378
379 // Check if already warned
380 if !vm.is_none(&registry) && already_warned(&registry, key.clone(), false, vm)? {
381 return Ok(());
382 }
383
384 // Get filter action
385 let action = get_filter(
386 category.as_object().to_owned(),
387 text.clone().into(),
388 lineno,
389 module,
390 vm,
391 )?;
392 let action_str = PyStrRef::try_from_object(vm, action)

Callers 1

warn_with_skipFunction · 0.70

Calls 15

normalize_moduleFunction · 0.85
already_warnedFunction · 0.85
get_filterFunction · 0.85
get_once_registryFunction · 0.85
update_registryFunction · 0.85
call_show_warningFunction · 0.85
fast_isinstanceMethod · 0.80
to_strMethod · 0.80
ErrClass · 0.50
is_noneMethod · 0.45
strMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected