Skip to content

Commit 43a7245

Browse files
committed
locals() return copy of locals dictionary
Return copy of locals so that local variables does not change even if locals() values is changed Fixes #1356
1 parent 8bce893 commit 43a7245

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

vm/src/builtins.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ fn builtin_len(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult {
366366
}
367367

368368
fn builtin_locals(vm: &VirtualMachine) -> PyDictRef {
369-
vm.get_locals()
369+
let locals = vm.get_locals();
370+
locals.copy(vm).into_ref(vm)
370371
}
371372

372373
fn builtin_max(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {

vm/src/obj/objdict.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ impl PyDictRef {
279279
}
280280
}
281281

282-
fn copy(self, _vm: &VirtualMachine) -> PyDict {
282+
pub fn copy(self, _vm: &VirtualMachine) -> PyDict {
283283
PyDict {
284284
entries: self.entries.clone(),
285285
}

0 commit comments

Comments
 (0)