Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #50745 > unrolled thread

Re: Is this a bug?

Started byJack Bates <tdhfwh@nottheoilrig.com>
First post2013-07-16 08:25 -0700
Last post2013-07-16 08:25 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Is this a bug? Jack Bates <tdhfwh@nottheoilrig.com> - 2013-07-16 08:25 -0700

#50745 — Re: Is this a bug?

FromJack Bates <tdhfwh@nottheoilrig.com>
Date2013-07-16 08:25 -0700
SubjectRe: Is this a bug?
Message-ID<mailman.4773.1373988344.3114.python-list@python.org>
On 15/07/13 09:13 AM, Joshua Landau wrote:
> On 15 July 2013 16:50, Jack Bates <tdhfwh@nottheoilrig.com> wrote:
>> Hello,
>>
>> Is the following code supposed to be an UnboundLocalError?
>> Currently it assigns the value 'bar' to the attribute baz.foo
>>
>>     foo = 'bar'
>>     class baz:
>>        foo = foo
>
> If so, then no. Assignments inside class bodies are special-cased in
> Python. This is because all assignments refer to properties of "self"
> on the LHS but external things too on the RHS. This is why you can do
> "def x(): ..." instead of "def self.x(): ..." or some other weird
> thing. There's also some extra special stuff that goes on.
>
> In order to make this an UnboundLocalError, lots of dramatic and
> unhelpful changes would have to take place, hence the current
> behaviour. The current behaviour is useful, too.

Ah, thank you Chris Angelico for explaining how this is like what 
happens with default arguments to a function and Joshua Landau for 
pointing out how assignments inside class bodies refer to properties of 
"self" on the LHS. It makes sense now. Only I'm struggling to find where 
the behavior is defined in the language reference. Can someone please 
help point me to where in the language reference this is discussed? I've 
been hunting through the section on naming and binding:

 
http://docs.python.org/3/reference/executionmodel.html#naming-and-binding

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web