Nuitka: The locals() function could be evaluated in the wrong context, e.g. in dict comprehension
0.6.8.4 (pip version) Python: 3.8.2 (default, Apr 27 2020, 15:53:34) Executable: /home/jack/oggreader/venv/bin/python OS: Linux Arch: x86_64
returning locals() from comprehension returns empty dict without warnings
from typing import Dict, Any
def foo() -> Dict[str,Any]:
bar: str = "asd"
return {x:y for x,y in locals().items()}
print(foo())
prints {}
copying the locals() to var solves the problem
from typing import Dict, Any
def foo() -> Dict[str,Any]:
bar: str = "asd"
copy = locals()
return {x:y for x,y in copy.items()}
print(foo())
prints {‘bar’: ‘asd’}
without comprehension everything works as expected
from typing import Dict, Any
def foo() -> Dict[str,Any]:
bar: str = "asd"
return locals()
print(foo())
prints {‘bar’: ‘asd’}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (14 by maintainers)
I made a pre-release with this contained. This has drawn more and more circles, esp. as the code turned out to now highlight weaknesses in the loop tracing, which had to be ironed out. However, all good now.