Author amaury.forgeotdarc
Recipients amaury.forgeotdarc
Date 2008-12-10.12:18:39
SpamBayes Score 6.15928e-09
Marked as misclassified No
Message-id <1228911523.24.0.570670634565.issue4617@psf.upfronthosting.co.za>
In-reply-to
Content
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():
        e

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

The reason is because of
http://www.python.org/dev/peps/pep-3110/#semantic-changes, 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.
History
Date User Action Args
2008-12-10 12:18:43amaury.forgeotdarcsetrecipients: + amaury.forgeotdarc
2008-12-10 12:18:43amaury.forgeotdarcsetmessageid: <1228911523.24.0.570670634565.issue4617@psf.upfronthosting.co.za>
2008-12-10 12:18:42amaury.forgeotdarclinkissue4617 messages
2008-12-10 12:18:41amaury.forgeotdarccreate