[Python-Dev] more timely detection of unbound locals

Eli Bendersky eliben at gmail.com
Mon May 9 17:01:06 CEST 2011


> I think you are making an unwarranted assumption about what is "more
> expected". I presume you are thinking that the expected behaviour is that
> foo() should:
>
> print global x (5)
> assign 1 to local x
> print local x (1)
>
> If we implemented this change, there would be no more questions about
> UnboundLocalError, but instead there would be lots of questions like "why is
> it that globals revert to their old value after I change them in a
> function?".
>

True, but this is less confusing and follows the rules in a more
straightforward way. x = 1 without a 'global x' assigns a local x, this make
sense and is similar to what happens in C where an inner declaration
temporarily shadows a global one.

Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20110509/20553648/attachment.html>


More information about the Python-Dev mailing list