Message228764
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. |
|
Date |
User |
Action |
Args |
2014-10-07 10:38:59 | mark.dickinson | set | recipients:
+ mark.dickinson, Miaou |
2014-10-07 10:38:59 | mark.dickinson | set | messageid: <1412678339.65.0.648678530754.issue22574@psf.upfronthosting.co.za> |
2014-10-07 10:38:59 | mark.dickinson | link | issue22574 messages |
2014-10-07 10:38:59 | mark.dickinson | create | |
|