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

Function call_show_warning

crates/vm/src/warn.rs:456–494  ·  view source on GitHub ↗
(
    category: PyTypeRef,
    text: PyStrRef,
    message: PyObjectRef,
    filename: PyStrRef,
    lineno: usize,
    lineno_obj: PyObjectRef,
    source_line: Option<PyObjectRef>,
    source: Optio

Source from the content-addressed store, hash-verified

454
455#[allow(clippy::too_many_arguments)]
456fn call_show_warning(
457 category: PyTypeRef,
458 text: PyStrRef,
459 message: PyObjectRef,
460 filename: PyStrRef,
461 lineno: usize,
462 lineno_obj: PyObjectRef,
463 source_line: Option<PyObjectRef>,
464 source: Option<PyObjectRef>,
465 vm: &VirtualMachine,
466) -> PyResult<()> {
467 let Some(show_fn) =
468 get_warnings_attr(vm, identifier!(&vm.ctx, _showwarnmsg), source.is_some())?
469 else {
470 return show_warning(filename, lineno, text, category, source_line, vm);
471 };
472 if !show_fn.is_callable() {
473 return Err(vm.new_type_error("warnings._showwarnmsg() must be set to a callable"));
474 }
475 let Some(warnmsg_cls) = get_warnings_attr(vm, identifier!(&vm.ctx, WarningMessage), false)?
476 else {
477 return Err(vm.new_runtime_error("unable to get warnings.WarningMessage"));
478 };
479
480 let msg = warnmsg_cls.call(
481 vec![
482 message,
483 category.into(),
484 filename.into(),
485 lineno_obj,
486 vm.ctx.none(),
487 vm.ctx.none(),
488 vm.unwrap_or_none(source),
489 ],
490 vm,
491 )?;
492 show_fn.call((msg,), vm)?;
493 Ok(())
494}
495
496fn show_warning(
497 filename: PyStrRef,

Callers 1

warn_explicitFunction · 0.85

Calls 5

get_warnings_attrFunction · 0.85
show_warningFunction · 0.85
is_callableMethod · 0.80
ErrClass · 0.50
callMethod · 0.45

Tested by

no test coverage detected