[New-bugs-announce] [issue26072] pdb fails to access variables closed over

Antony Lee report at bugs.python.org
Sun Jan 10 00:16:24 EST 2016


New submission from Antony Lee:

Consider the following example:

    def f(x=1):
        def g():
            y = 2
            raise Exception
        g()

    f()

$ python -mpdb -ccontinue example.py
<... traceback ...>
> /tmp/example.py(4)g()
-> raise Exception
(Pdb) p x
##### this can be worked around using "up"
*** NameError: name 'x' is not defined
(Pdb) p y
2
(Pdb) p (lambda: y)()
##### this is more awkward to work around, e.g. (lambda *, y=y: y)()
*** NameError: name 'y' is not defined

Use case: I wan to pass a lambda to a numerical optimizer, but the optimizer fails using the default starting point.  Within pdb, I'd like to pass a different starting point but the same lambda, to see whether this helps.

----------
components: Library (Lib)
messages: 257888
nosy: Antony.Lee
priority: normal
severity: normal
status: open
title: pdb fails to access variables closed over
versions: Python 3.5, Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26072>
_______________________________________


More information about the New-bugs-announce mailing list