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

Function caller

crates/vm/src/stdlib/typevar.rs:52–58  ·  view source on GitHub ↗

Get the module of the caller frame, similar to CPython's caller() function. Returns the module name or None if not found. Note: CPython's implementation (in typevarobject.c) gets the module from the frame's function object using PyFunction_GetModule(f->f_funcobj). However, RustPython's Frame doesn't store a reference to the function object, so we get the module name from the frame's globals dicti

(vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

50 /// RustPython's Frame doesn't store a reference to the function object, so we
51 /// get the module name from the frame's globals dictionary instead.
52 fn caller(vm: &VirtualMachine) -> Option<PyObjectRef> {
53 let frame = vm.current_frame()?;
54
55 // In RustPython, we get the module name from frame's globals
56 // This is similar to CPython's sys._getframe().f_globals.get('__name__')
57 frame.globals.get_item("__name__", vm).ok()
58 }
59
60 /// Set __module__ attribute for an object based on the caller's module.
61 /// This follows CPython's behavior for TypeVar and similar objects.

Callers 2

convert_openssl_errorFunction · 0.85
set_module_from_callerFunction · 0.85

Calls 3

current_frameMethod · 0.80
okMethod · 0.80
get_itemMethod · 0.45

Tested by

no test coverage detected