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 mark.dickinson
Recipients Miaou, mark.dickinson
Date 2014-10-07.10:38:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1412678339.65.0.648678530754.issue22574@psf.upfronthosting.co.za>
In-reply-to
Content
So while the behaviour is surprising, the language is behaving as designed:  the target of `del` is considered to be a local variable for the entire function definition.  (In much the same way, the targets of simple assignments are considered local, so if you'd assigned to "Foo" in the "if False:" block, you'd see the same error.)

The behaviour is documented here: https://docs.python.org/3.4/reference/executionmodel.html#naming-and-binding

Note particularly these bits:

"If a name is bound in a block, it is a local variable of that block, [...]"

"A target occurring in a del statement is also considered bound for this purpose [...]"

See also this FAQ: https://docs.python.org/3/faq/programming.html#id8

I wonder whether it's worth updating the FAQ to mention that `del` is considered to bind names in this way.
History
Date User Action Args
2014-10-07 10:38:59mark.dickinsonsetrecipients: + mark.dickinson, Miaou
2014-10-07 10:38:59mark.dickinsonsetmessageid: <1412678339.65.0.648678530754.issue22574@psf.upfronthosting.co.za>
2014-10-07 10:38:59mark.dickinsonlinkissue22574 messages
2014-10-07 10:38:59mark.dickinsoncreate