EDIT: I tested a few more things. It looks like this error only occurs with my company's internal python executable, not /bin/python
or an anaconda install. Would like to vote to close this.
If I break into the VS code python debugger (this is debugpy v1.6.6) and in the debug console run:
x = 1
[test for test in range(10) if x]
On the second line I get
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "<string>", line 1, in <listcomp>
NameError: name 'x' is not defined
Any ideas why this might be happening? Possibly related posts:
- https://github.com/Microsoft/vscode-python/issues/2110
- List comprehension scope error from Python debugger
The first link suggests the issue was resolved in ~2018, however I am experiencing it today on my work machine with version 2023.2 of the VS code python extension. Any ideas?
Info:
- VS code version: 1.79.2
- debugpy version: 1.6.6
- python: 3.8
Screenshot: