From 7c1174f816045040ed0d293d2bebe4b76e1a1b4f Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Fri, 28 Feb 2025 17:04:30 +0800 Subject: [PATCH] some fix --- src/public/modules.c | 4 ++-- tests/67_locals_vs_globals.py | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/public/modules.c b/src/public/modules.c index fd90b3ad..9adcd670 100644 --- a/src/public/modules.c +++ b/src/public/modules.c @@ -508,14 +508,14 @@ void py_newglobals(py_Ref out) { void py_newlocals(py_Ref out) { Frame* frame = pk_current_vm->top_frame; if(!frame) { - py_newglobals(out); + py_newdict(out); return; } if(frame->is_locals_special) { switch(frame->locals->type) { case tp_locals: frame = frame->locals->_ptr; break; case tp_dict: *out = *frame->locals; return; - case tp_nil: py_newglobals(out); return; + case tp_nil: py_newdict(out); return; default: c11__unreachable(); } } diff --git a/tests/67_locals_vs_globals.py b/tests/67_locals_vs_globals.py index 749837ea..992f65a1 100644 --- a/tests/67_locals_vs_globals.py +++ b/tests/67_locals_vs_globals.py @@ -6,7 +6,6 @@ my_locals = {"b": 2} # With user-defined locals: exec(""" import sys -assert locals() != globals() assert "sys" in locals() assert "sys" not in globals() assert "a" not in locals() @@ -18,7 +17,6 @@ assert "b" not in globals() # print(b) assert (b == 2), b def main(): - assert locals() != globals() assert "sys" not in locals() # not the same `locals()` as the outer scope assert "sys" not in globals() # and `sys` isn't in `globals()`, same as before assert "b" not in locals() # again, not the same `locals()` as the outer scope @@ -32,7 +30,7 @@ assert "sys" not in globals() # With default locals: exec(""" import sys -assert "sys" in locals() +assert locals() == {} assert "sys" in globals() def main(): assert "sys" not in locals() # not the same locals as the outer scope