classification
Title: unexpected behavior with exception variable
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.1, Python 3.2, Python 3.3
process
Status: closed Resolution: duplicate
Dependencies: Superseder: except-as in Py3 eats variables
View: 8130
Assigned To: Nosy List: Mathias.Svensson, eric.snow, ezio.melotti, santoso.wijaya
Priority: normal Keywords:

Created on 2011-05-12 17:52 by Mathias.Svensson, last changed 2011-05-13 07:31 by mark.dickinson. This issue is now closed.

Files
File name Uploaded Description Edit
test.py Mathias.Svensson, 2011-05-12 17:52
Messages (4)
msg135845 - (view) Author: Mathias Svensson (Mathias.Svensson) Date: 2011-05-12 17:52
Current behavior:
In the very simple attached example an existing variable-name is used as the target in the except-part of a try-statement. The existing variable is deleted if an exception is throw.

Excepted behavior:
The only reasonable behaviors are keeping the original variable or keeping the exception. The current behavior is very unintuitive.
msg135848 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2011-05-12 18:16
Duplicate of issue8130.

"When an exception has been assigned using as target, it is cleared at the end of the except clause." [1]

See: 
[1] http://docs.python.org/py3k/reference/compound_stmts.html#the-try-statement
[2] http://www.python.org/dev/peps/pep-3110/#semantic-changes (discussed in issue4617)
msg135849 - (view) Author: Santoso Wijaya (santoso.wijaya) * Date: 2011-05-12 18:16
Looks like a regression from 2.x.

On 2.7:
Python 2.7.1 (r271:86832, Nov 27 2010, 17:19:03) [MSC v.1500 64 bit (AMD64)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> e = True
>>> try: raise Exception()
... except Exception as e: pass
...
>>> print repr(e)
Exception()

On 3.2:
Python 3.2 (r32:88445, Feb 20 2011, 21:30:00) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> e = True
>>> try: raise Exception()
... except Exception as e: pass
...
>>> print(repr(e))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'e' is not defined
msg135851 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-05-12 18:27
Closing as duplicate.
History
Date User Action Args
2011-05-13 07:31:31mark.dickinsonsetsuperseder: except-as in Py3 eats variables
2011-05-12 18:27:46ezio.melottisetstatus: open -> closed

nosy: + ezio.melotti
messages: + msg135851

resolution: duplicate
stage: resolved
2011-05-12 18:16:35santoso.wijayasetnosy: + santoso.wijaya

messages: + msg135849
versions: + Python 3.1, Python 3.3
2011-05-12 18:16:01eric.snowsetnosy: + eric.snow
messages: + msg135848
2011-05-12 17:52:56Mathias.Svenssoncreate