Mark Dickinson added the comment: 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. ---------- nosy: +mark.dickinson _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue22574> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com