New GitHub issue #100185 from e-baumer:<br>
<hr>
<pre>
# Bug report
I receive a `NameError` for a variable defined in a function scope when trying to execute a dictionary comprehension in pdb. The variable is part of the local scope as seen with `locals()`
For the following code:
```python
def somefunc(fltrlist):
d1 = {
"A": [1, 2, 3],
"B": [4, 5, 6],
"C": [7, 8, 9]
}
import pdb;pdb.set_trace()
d2 = {
k: v for k, v in d1.items() if k in fltrlist
}
klist = ["A", "B"]
somefunc(klist)
```
When I enter pdb and try to run the dictionary comprehension I get the following:
```bash
➜ python3 scope_test.py
> scope_test.py(10)somefunc()
-> d2 = {
(Pdb) {k: v for k, v in d1.items() if k in fltrlist}
*** NameError: name 'fltrlist' is not defined
(Pdb)
```
The variable is part of the local scope,
```bash
(Pdb) locals()
{'d1': {'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]}, 'pdb': <module 'pdb' from '/usr/lib/python3.10/pdb.py'>, 'fltrlist': ['A', 'B']}
(Pdb) fltrlist
['A', 'B']
(Pdb)
```
If I try the same thing but not defined within a function it works.
```python
fltrlist = ["A", "B"]
d1 = {
"A": [1, 2, 3],
"B": [4, 5, 6],
"C": [7, 8, 9]
}
import pdb;pdb.set_trace()
d2 = {
k: v for k, v in d1.items() if k in fltrlist
}
```
When in pdb the dictionary comprehension works fine.
```bash
➜ python3 scope_test.py
> scope_test.py(11)<module>()
-> d2 = {
(Pdb) {k: v for k, v in d1.items() if k in fltrlist}
{'A': [1, 2, 3], 'B': [4, 5, 6]}
(Pdb)
```
# Your environment
- Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] on linux
- Pop!_OS 22.04 (jammy) - 6.0.6-76060006-generic
</pre>
<hr>
<a href="https://github.com/python/cpython/issues/100185">View on GitHub</a>
<p>Labels: type-bug</p>
<p>Assignee: </p>