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 <rep...@bugs.python.org>
<http://bugs.python.org/issue26072>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to