[Python-Dev] Unbound locals in class scopes
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:
>>> 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
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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev