File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff 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) {
You can’t perform that action at this time.
0 commit comments