Skip to content

Commit bc7e50e

Browse files
committed
warn
1 parent 9d5cc1d commit bc7e50e

File tree

1 file changed

+10
-31
lines changed

1 file changed

+10
-31
lines changed

crates/vm/src/warn.rs

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -406,39 +406,18 @@ fn setup_context(
406406
(f.globals.clone(), f.code.source_path, f.f_lineno())
407407
} else if let Some(frame) = vm.current_frame() {
408408
// We have a frame but it wasn't found during stack walking
409-
(frame.globals.clone(), vm.ctx.intern_str("sys"), 1)
409+
(frame.globals.clone(), vm.ctx.intern_str("<sys>"), 1)
410410
} else {
411-
// No frames on the stack - we're in interpreter shutdown or similar state
412-
// Use __main__ globals if available, otherwise skip the warning
413-
match vm
411+
// No frames on the stack - use sys.__dict__ (interp->sysdict in CPython)
412+
let globals = vm
414413
.sys_module
415-
.get_attr(identifier!(vm, modules), vm)
416-
.and_then(|modules| modules.get_item(vm.ctx.intern_str("__main__"), vm))
417-
.and_then(|main_mod| main_mod.get_attr(identifier!(vm, __dict__), vm))
418-
{
419-
Ok(globals) => {
420-
if let Ok(dict) = globals.downcast::<crate::builtins::PyDict>() {
421-
(dict, vm.ctx.intern_str("sys"), 1)
422-
} else {
423-
// Cannot get globals, skip warning
424-
return Ok((
425-
vm.ctx.intern_str("sys").to_owned(),
426-
1,
427-
None,
428-
vm.ctx.new_dict().into(),
429-
));
430-
}
431-
}
432-
Err(_) => {
433-
// Cannot get __main__ globals, skip warning
434-
return Ok((
435-
vm.ctx.intern_str("sys").to_owned(),
436-
1,
437-
None,
438-
vm.ctx.new_dict().into(),
439-
));
440-
}
441-
}
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)
442421
};
443422

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

0 commit comments

Comments
 (0)