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

Function get_warnings_attr

crates/vm/src/warn.rs:113–141  ·  view source on GitHub ↗
(
    vm: &VirtualMachine,
    attr_name: &'static PyStrInterned,
    try_import: bool,
)

Source from the content-addressed store, hash-verified

111}
112
113fn get_warnings_attr(
114 vm: &VirtualMachine,
115 attr_name: &'static PyStrInterned,
116 try_import: bool,
117) -> PyResult<Option<PyObjectRef>> {
118 let module = if try_import
119 && !vm
120 .state
121 .finalizing
122 .load(core::sync::atomic::Ordering::SeqCst)
123 {
124 match vm.import("warnings", 0) {
125 Ok(module) => module,
126 Err(_) => return Ok(None),
127 }
128 } else {
129 match vm.sys_module.get_attr(identifier!(vm, modules), vm) {
130 Ok(modules) => match modules.get_item(vm.ctx.intern_str("warnings"), vm) {
131 Ok(module) => module,
132 Err(_) => return Ok(None),
133 },
134 Err(_) => return Ok(None),
135 }
136 };
137 match module.get_attr(attr_name, vm) {
138 Ok(attr) => Ok(Some(attr)),
139 Err(_) => Ok(None),
140 }
141}
142
143/// Get the warnings filters list from sys.modules['warnings'].filters,
144/// falling back to vm.state.warnings.filters.

Callers 4

get_warnings_filtersFunction · 0.85
get_default_actionFunction · 0.85
get_once_registryFunction · 0.85
call_show_warningFunction · 0.85

Calls 6

intern_strMethod · 0.80
SomeClass · 0.50
loadMethod · 0.45
importMethod · 0.45
get_attrMethod · 0.45
get_itemMethod · 0.45

Tested by

no test coverage detected