This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xdegaye
Recipients Saim Raza, SilentGhost, barry, xdegaye
Date 2019-04-06.19:48:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1554580082.12.0.893294687173.issue36537@roundup.psfhosted.org>
In-reply-to
Content
This is not a bug.
On the first pdb session from the OP:

True
--Return--
> <ipython-input-2-9d1238ac9b7a>(5)<module>()->None
-> import pdb; pdb.set_trace()
(Pdb) print("err" in locals())
False          <-------------- BUG??

Pdb has stopped on a '--Return--' line event, so we are already outside the scope of the except clause and the 'err' local variable cannot be accessed outside the except block. The following code snippet shows that pdb stops at the line following the set_trace() call:

==================
def foo():
    try:
        1/0
    except Exception as err:
        import pdb; pdb.set_trace()
    x= 1

foo()
==================

And the corresponding pdb session:

$ python foo.py
> /path/to/foo.py(6)foo()
-> x= 1
(Pdb) err
*** NameError: name 'err' is not defined
(Pdb)
History
Date User Action Args
2019-04-06 19:48:02xdegayesetrecipients: + xdegaye, barry, SilentGhost, Saim Raza
2019-04-06 19:48:02xdegayesetmessageid: <1554580082.12.0.893294687173.issue36537@roundup.psfhosted.org>
2019-04-06 19:48:02xdegayelinkissue36537 messages
2019-04-06 19:48:01xdegayecreate