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 Saim Raza
Recipients Saim Raza
Date 2019-04-05.18:43:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1554489816.2.0.715067150447.issue36537@roundup.psfhosted.org>
In-reply-to
Content
If pdb.set_trace() is the last statement in the first code snippet, variable 'err' is (wrongly?) excluded from locals(). Adding any code after the pdb.set_trace() statement makes 'err' available in locals.

In [2]: try:
   ...:     raise ValueError("I am ValueError")
   ...: except ValueError as err:
   ...:     print("err" in locals())
   ...:     import pdb; pdb.set_trace()
   ...:
True
--Return--
> <ipython-input-2-9d1238ac9b7a>(5)<module>()->None
-> import pdb; pdb.set_trace()
(Pdb) print("err" in locals())
False          <-------------- BUG??
(Pdb) c

In [3]: try:
   ...:     raise ValueError("I am ValueError")
   ...: except ValueError as err:
   ...:     print("err" in locals())
   ...:     import pdb; pdb.set_trace()
   ...:     import os # Dummy code - makes variable 'err' available inside the debugger.
   ...:
True
> <ipython-input-3-3cefa7fe6ddd>(6)<module>()->None
-> import os # Dummy code - makes variable err available inside debugger
(Pdb) print("err" in locals())
True

In [4]: sys.version_info
Out[4]: sys.version_info(major=3, minor=7, micro=3, releaselevel='final', serial=0)

FTR, the variable 'err' is available in both cases in case of Python 2.7. Also, this happens with ipdb as well.

Please note that I am aware that I need to assign the variable 'err' to some variable inside the except block to access it outside the except block. However, the pdb statement is still inside the except block in both cases.
History
Date User Action Args
2019-04-05 18:43:36Saim Razasetrecipients: + Saim Raza
2019-04-05 18:43:36Saim Razasetmessageid: <1554489816.2.0.715067150447.issue36537@roundup.psfhosted.org>
2019-04-05 18:43:36Saim Razalinkissue36537 messages
2019-04-05 18:43:36Saim Razacreate