[New-bugs-announce] [issue39841] "as" variable in except block deletes local variables with same name

Alan Robertson report at bugs.python.org
Tue Mar 3 15:59:02 EST 2020


New submission from Alan Robertson <alanr at unix.sh>:

When an exception "as" variable occurs, it deletes local variables with the same name. This is certainly surprising, and doesn't appear to be a documented behavior (but maybe I don't know where to look). The word "bug" comes to mind.  The following few lines of code illustrate it nicely:

def testme():
    err = Exception("nothing worked")
    try:
        raise ValueError("no value")
    except ValueError as err:
        pass
    print(err)

testme()

----------
components: Interpreter Core
files: foo.py
messages: 363300
nosy: alanr
priority: normal
severity: normal
status: open
title: "as" variable in except block deletes local variables with same name
versions: Python 3.7
Added file: https://bugs.python.org/file48946/foo.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39841>
_______________________________________


More information about the New-bugs-announce mailing list