New submission from Xinmeng Xia <xi...@smail.nju.edu.cn>:
Normally after executing a piece of code in a function, locals() should contain the local variables and these variables can be reassigned next. In the following code, "attr" should be found in locals(). Actually, it can not be found in either locals() or globals() after executing code "attr = 1". This program triggers a keyError. I think something wrong during handling locals(). ================================ def foo(): exec("attr = 1") a = locals()['attr'] attr = 2 foo() ================================ Reported Error: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 3, in foo KeyError: 'attr' Expected output: This test program should work well. The value of a is 1 and the value of attr is 2 after execution. No error is reported. Python version: python3.10, Ubuntu 16.04 ---------- components: Interpreter Core messages: 405660 nosy: xxm priority: normal severity: normal status: open title: Variable reassginment triggers incorrect behaviors of locals() type: behavior versions: Python 3.10 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue45707> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com