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.

Title: unexpected behavior with exception variable
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.1, Python 3.2, Python 3.3
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 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit 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]

[2] (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
Type "help", "copyright", "credits" or "license" for more information.
>>> e = True
>>> try: raise Exception()
... except Exception as e: pass
>>> print repr(e)

On 3.2:
Python 3.2 (r32:88445, Feb 20 2011, 21:30:00) [MSC v.1500 64 bit (AMD64)] on win
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.
Date User Action Args
2022-04-11 14:57:17adminsetgithub: 56273
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