ipdb
ipdb copied to clipboard
Closures are not formed properly in interactive mode
I have found an issue where closures are not being formed properly when in interactive mode of an ipdb
session. Namely, variables defined in the session are not visible to function closures.
Example:
$ python
Python 3.8.12 (default, Dec 18 2023, 10:05:54)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ipdb; ipdb.set_trace()
--Return--
None
> <stdin>(1)<module>()
ipdb> x = None; [x for _ in [None]] # Note how this works when not in interactive mode
[None]
ipdb> interact
*interactive*
17:09:53 In [1] x = None; [x for _ in [None]]
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
File <ipython-input-1-92de5d84d68a>:1
----> 1 x = None; [x for _ in [None]]
File <ipython-input-1-92de5d84d68a>:1, in <listcomp>(.0)
----> 1 x = None; [x for _ in [None]]
NameError: name 'x' is not defined
Another example:
17:11:13 In [1] x = None; f = lambda:x; f()
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
File <ipython-input-1-95925a6f61cc>:1
----> 1 x = None; f = lambda:x; f()
File <ipython-input-1-95925a6f61cc>:1, in <lambda>()
----> 1 x = None; f = lambda:x; f()
NameError: name 'x' is not defined
These two examples work correctly inside interactive mode of pdb
, or when in a normal ipython/python session.
Environment Info:
-
ipdb
: 0.13.13 -
python
: 3.8.12
@brandtbucher This is the issue we saw together