Loax Loax - 4 months ago 10x
Python Question

Possible bug in pdb module in Python 3 when using list generators

After running this code in Python 3:

import pdb

def foo():
nums = [1, 2, 3]
a = 5


The following expressions work:

(Pdb) print(nums)
[1, 2, 3]

(Pdb) print(a)

(Pdb) [x for x in nums]
[1, 2, 3]

but the following expression fails:

(Pdb) [x*a for x in nums]
*** NameError: global name 'a' is not defined

The above works fine in Python 2.7.

Is this a bug or I am missing something?

Update: See the new accepted answer. This has been a bug and has been addressed now.


if you type interact in your [i]pdb session, you get an interactive session, and list comprehensions do work as expected in this mode

source: http://bugs.python.org/msg215963