You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pdb NameError in generator param and list comprehension #80052
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2019-02-01.00:25:49.653>labels= ['interpreter-core', '3.7']
title='Pdb NameError in generator param and list comprehension'updated_at=<Date2019-02-01.05:21:32.902>user='https://bugs.python.org/jayanth'
I get a NameError for a variable in the generator param of a function or in a list comprehension. See example below. The variable is available to the program, but not to the interactive Pdb shell.
$ python3
Python 3.7.2 (default, Jan 13 2019, 12:50:15)
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>
$ python3 /tmp/test.py
>/tmp/test.py(5)main()
->foriiin range(nn):
(Pdb) n
>/tmp/test.py(6)main()
-> num = sum(xx[jj] forjjin range(nn))
(Pdb) sum(xx[jj] forjjin range(nn))
*** NameError: name 'xx' is not defined
(Pdb) [xx[jj] forjjin range(nn)]
*** NameError: name 'xx' is not defined
(Pdb) c
xx=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
FWIW python3 is a homebrew installation. I had the same issue with 3.7.0 as well (also homebrew):
Python 3.7.0 (default, Sep 18 2018, 18:47:22)
[Clang 9.1.0 (clang-902.0.39.2)] on darwin
Thanks for the report. This seems related to bpo-21161 and bpo-26072 that contain explanation about scope where exec is called with the code and patches that fix this issue. As a possible workaround in the issues you can use "interact" command to get to a REPL where you can evaluate and exit back to pdb.
jayanth commented on Feb 1, 2019
jayanthmannequin
MannequinAuthor
More actions
Thanks for the "interact" tip.
FWIW, I see this issue in 2.7.10 as well. Although the list comprehension works.
$ python
Python 2.7.10 (default, Oct 6 2017, 22:29:07)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> ^D
$ python /tmp/test2.py
>/tmp/test2.py(5)main()
->foriiin range(nn):
(Pdb) n
>/tmp/test2.py(6)main()
-> num = sum(xx[jj] forjjin range(nn))
(Pdb) sum(xx[jj] forjjin range(nn))
*** NameError: global name 'xx' is not defined
(Pdb) [xx[jj] forjjin range(nn)]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
(Pdb) c
('xx', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
Activity
jayanth commentedon Feb 1, 2019
I get a NameError for a variable in the generator param of a function or in a list comprehension. See example below. The variable is available to the program, but not to the interactive Pdb shell.
# Test file:
$ python3
Python 3.7.2 (default, Jan 13 2019, 12:50:15)
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
FWIW python3 is a homebrew installation. I had the same issue with 3.7.0 as well (also homebrew):
Python 3.7.0 (default, Sep 18 2018, 18:47:22)
[Clang 9.1.0 (clang-902.0.39.2)] on darwin
tirkarthi commentedon Feb 1, 2019
Thanks for the report. This seems related to bpo-21161 and bpo-26072 that contain explanation about scope where exec is called with the code and patches that fix this issue. As a possible workaround in the issues you can use "interact" command to get to a REPL where you can evaluate and exit back to pdb.
jayanth commentedon Feb 1, 2019
Thanks for the "interact" tip.
FWIW, I see this issue in 2.7.10 as well. Although the list comprehension works.
$ python Python 2.7.10 (default, Oct 6 2017, 22:29:07) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> ^D# test2.py
gaogaotiantian commentedon May 6, 2024
Fix by PEP 709 + #111094