[Python-Dev] Unbound locals in class scopes

Ivan Levkivskyi levkivskyi at gmail.com
Sun Jun 21 18:22:59 CEST 2015

On 20 June 2015 at 18:39, Ron Adam <ron3200 at gmail.com> wrote:

> On 06/20/2015 12:12 PM, Ron Adam wrote:
>> On 06/20/2015 02:51 AM, Ivan Levkivskyi wrote:
>  Guido said 13 years ago that this behavior should not be changed:
>>> https://mail.python.org/pipermail/python-dev/2002-April/023428.html,
>>> however, things changed a bit in Python 3.4 with the introduction of the
>>> LOAD_CLASSDEREF opcode. I just wanted to double-check whether it is
>>> still a
>>> desired/expected behavior.
>  Guido's comment still stands as far as references inside methods work in
>> regards to the class body. (they must use a self name to access the class
>> name space.) But the execution of the class body does use lexical scope,
>> otherwise it would print xtop instead of xlocal here.
> Minor corrections:
> Methods can access but not write to the class scope without using self.
> So that is also equivalent to the function version using type().  The
> methods capture the closure they were defined in, which is interesting.
> And the self name refers to the object's names space not the class name
> space.

It is still not clear whether Guido's comment still stands for not raising
an UnboundLocalError in class definitions but using globals instead.
This is the only questionable point for me currently.

> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/levkivskyi%40gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150621/f3f2aa61/attachment.html>

More information about the Python-Dev mailing list