[issue35871] Pdb NameError in generator param and list comprehension

2019-01-31 Thread Jayanth Raman


Jayanth Raman  added the comment:

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()
-> for ii in range(nn):
(Pdb) n
> /tmp/test2.py(6)main()
-> num = sum(xx[jj] for jj in range(nn))
(Pdb) sum(xx[jj] for jj in range(nn))
*** NameError: global name 'xx' is not defined
(Pdb) [xx[jj] for jj in 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])

# test2.py

def main(nn=10):
xx = list(range(nn))
import pdb; pdb.set_trace()
for ii in range(nn):
num = sum(xx[jj] for jj in range(nn))
print('xx', xx)

if __name__ == '__main__':
main()

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35871] Pdb NameError in generator param and list comprehension

2019-01-31 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

Thanks for the report. This seems related to issue21161 and issue26072 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.

--
nosy: +xdegaye, xtreak

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35871] Pdb NameError in generator param and list comprehension

2019-01-31 Thread Jayanth Raman


New submission from Jayanth Raman :

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:

def main(nn=10):
xx = list(range(nn))
breakpoint()
for ii in range(nn):
num = sum(xx[jj] for jj in range(nn))
print(f'xx={xx}')

if __name__ == '__main__':
main()


$ 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()
-> for ii in range(nn):
(Pdb) n
> /tmp/test.py(6)main()
-> num = sum(xx[jj] for jj in range(nn))
(Pdb) sum(xx[jj] for jj in range(nn))
*** NameError: name 'xx' is not defined
(Pdb) [xx[jj] for jj in 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

--
components: Interpreter Core
messages: 334639
nosy: jayanth
priority: normal
severity: normal
status: open
title: Pdb NameError in generator param and list comprehension
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com