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.

Author amaury.forgeotdarc
Recipients amaury.forgeotdarc
Date 2008-12-10.12:18:39
SpamBayes Score 6.15928e-09
Marked as misclassified No
Message-id <>
This issue comes from issue4613. The following code raises a
SyntaxError("can not delete variable 'e' referenced in nested scope"):

def f():
    e = None
    def g():

    except Exception as e:
        pass # SyntaxError here???

The reason is because of, a "del e"
statement is inserted.

The above code is correct, and should work.
I suggest that the limitation: "can not delete variable referenced in
nested scope" could be removed. 

After all, the "variable referenced" has no value before it is set,
accessing it raises either NameError("free variable referenced before
assignment in enclosing scope") or UnboundLocalError("local variable
referenced before assignment")

The Attached patch adds a DELETE_DEREF opcode, that removes the value of
a cell variable, and put it in a "before assignment" state.

Some compiler experts should review it. Few regressions are possible,
since the new opcode is emitted where a SyntaxError was previously
raised. The patch could also be applied to 2.7, even if it is less
critical there.

Tests are to come, but I'd like other's suggestions.
Date User Action Args
2008-12-10 12:18:43amaury.forgeotdarcsetrecipients: + amaury.forgeotdarc
2008-12-10 12:18:43amaury.forgeotdarcsetmessageid: <>
2008-12-10 12:18:42amaury.forgeotdarclinkissue4617 messages
2008-12-10 12:18:41amaury.forgeotdarccreate