blueloveTH 1 年間 前
コミット
7c1174f816
2 ファイル変更3 行追加5 行削除
  1. 2 2
      src/public/modules.c
  2. 1 3
      tests/67_locals_vs_globals.py

+ 2 - 2
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();
         }
     }

+ 1 - 3
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