[issue8130] except-as in Py3 eats variables
Ezio Melotti ezio.melo...@gmail.com added the comment: In this case I don't see much difference between deleting a variable or assigning it to something else. This code works on both Python 2 and 3: e = 'test' try: pass# no errors raised here ... except Exception as e: pass # this is not executed ... e 'test' If you do this instead: e = 'test' try: raise ValueError# raise the error ... except Exception as e: pass # this is executed ... On both 2.x and 3.x 'e' doesn't refer to 'test' anymore in the moment that the exception is captured by the except, so what happens next to the new e is not related to what the old e was. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8130 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8130] except-as in Py3 eats variables
Florent Xicluna florent.xicl...@gmail.com added the comment: See also #4617, with some patch. -- nosy: +flox superseder: - SyntaxError when free variable name is also an exception target ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8130 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8130] except-as in Py3 eats variables
New submission from Stefan Behnel sco...@users.sourceforge.net: Python 3.2a0 (py3k:78205M, Feb 16 2010, 17:32:08) [GCC 4.4.1] on linux2 Type help, copyright, credits or license for more information. e = None [50279 refs] e [50279 refs] try: raise ValueError ... except ValueError as e: pass ... [50277 refs] e Traceback (most recent call last): File stdin, line 1, in module NameError: name 'e' is not defined [50277 refs] Same for 3.1.1. Note how the refcount is going down after the try-except. -- components: Interpreter Core messages: 100993 nosy: scoder severity: normal status: open title: except-as in Py3 eats variables type: behavior versions: Python 3.1, Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8130 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8130] except-as in Py3 eats variables
Ezio Melotti ezio.melo...@gmail.com added the comment: This is a not a bug and it's documented: http://docs.python.org/py3k/reference/compound_stmts.html#the-try-statement The solution is to assign the value to another variable: try: raise ValueError ... except ValueError as e: exc = e ... exc ValueError() e Traceback (most recent call last): File stdin, line 1, in module NameError: name 'e' is not defined -- nosy: +ezio.melotti priority: - normal resolution: - invalid stage: - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8130 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8130] except-as in Py3 eats variables
Stefan Behnel sco...@users.sourceforge.net added the comment: I knew that the variable was supposed to go out of scope when leaving the except block, but I wasn't aware that this was supposed to be done using (the equivalent of) a 'del'. Were the side-effects of deleting variables defined outside of the try-except considered negligible at the time? I can't see a warning about that in the docs. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8130 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com