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

Function is_stdlib_module_name

crates/vm/src/import.rs:352–366  ·  view source on GitHub ↗

Check if a module name is in sys.stdlib_module_names. Takes the original __name__ object to preserve str subclass behavior. Propagates errors (e.g. TypeError for unhashable str subclass).

(name: &PyObjectRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

350/// Takes the original __name__ object to preserve str subclass behavior.
351/// Propagates errors (e.g. TypeError for unhashable str subclass).
352pub(crate) fn is_stdlib_module_name(name: &PyObjectRef, vm: &VirtualMachine) -> PyResult<bool> {
353 let stdlib_names = match vm.sys_module.get_attr("stdlib_module_names", vm) {
354 Ok(names) => names,
355 Err(_) => return Ok(false),
356 };
357 if !stdlib_names.class().fast_issubclass(vm.ctx.types.set_type)
358 && !stdlib_names
359 .class()
360 .fast_issubclass(vm.ctx.types.frozenset_type)
361 {
362 return Ok(false);
363 }
364 let result = vm.call_method(&stdlib_names, "__contains__", (name.clone(),))?;
365 result.try_to_bool(vm)
366}
367
368/// PyImport_ImportModuleLevelObject
369pub(crate) fn import_module_level(

Callers 2

import_fromMethod · 0.85
getattr_innerMethod · 0.85

Calls 6

fast_issubclassMethod · 0.80
try_to_boolMethod · 0.80
get_attrMethod · 0.45
classMethod · 0.45
call_methodMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected