Skip to content

Commit c0489c6

Browse files
committed
fix warn
1 parent 3942072 commit c0489c6

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

crates/vm/src/warn.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,20 @@ fn setup_context(
404404

405405
let (globals, filename, lineno) = if let Some(f) = f {
406406
(f.globals.clone(), f.code.source_path, f.f_lineno())
407+
} else if let Some(frame) = vm.current_frame() {
408+
// We have a frame but it wasn't found during stack walking
409+
(frame.globals.clone(), vm.ctx.intern_str("<sys>"), 1)
407410
} else {
408-
(vm.current_globals().clone(), vm.ctx.intern_str("sys"), 1)
411+
// No frames on the stack - use sys.__dict__ (interp->sysdict)
412+
let globals = vm
413+
.sys_module
414+
.as_object()
415+
.get_attr(identifier!(vm, __dict__), vm)
416+
.and_then(|d| {
417+
d.downcast::<crate::builtins::PyDict>()
418+
.map_err(|_| vm.new_type_error("sys.__dict__ is not a dictionary"))
419+
})?;
420+
(globals, vm.ctx.intern_str("<sys>"), 0)
409421
};
410422

411423
let registry = if let Ok(registry) = globals.get_item(__warningregistry__, vm) {

0 commit comments

Comments
 (0)