New submission from Saim Raza <saimors...@gmail.com>:

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.

----------
components: Library (Lib)
messages: 339510
nosy: Saim Raza
priority: normal
severity: normal
status: open
title: except statement block incorrectly assumes end of scope(?).
type: behavior
versions: Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue36537>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to