ipython / ipython

Official repository for IPython itself. Other repos in the IPython organization contain things like the website, documentation builds, etc.

Home Page:https://ipython.readthedocs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot access local variable in list comprehension while in function

NejsemTonda opened this issue · comments

I was debugging some code using IPython embed function but I got an error I believe is bug.

from IPython import embed

def foo():
    l = list(range(100))
    k = [l[i] for i in range(len(l))]
    embed()

foo()

when in interactive shell I can access the 'l' variable,

In [1]: l #works fine

but cannot access it in list comprehension '[l[i] for i in range(len(l))]'.

In [2]: [l[i] for i in l] #throws an error

outside function it works fine.
Is this error on my side?

I think there is already an issue open about that (maybe for the debugger).

We've know about similar things for a loooong time, but I'm not sure I understand why or how to fix it.

So yes it's a bug, just unclear what to do about it.