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


Groups > comp.lang.python > #50745

Re: Is this a bug?

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <tdhfwh@nottheoilrig.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'attribute': 0.07; 'subject:bug': 0.07; 'arguments': 0.09; 'cc:addr:python-list': 0.11; 'useful,': 0.14; 'changes': 0.15; 'ah,': 0.16; 'assignments': 0.16; 'assigns': 0.16; 'behaviour.': 0.16; 'lhs': 0.16; 'naming': 0.16; 'received:192.168.0.11': 0.16; 'unhelpful': 0.16; 'weird': 0.16; 'language': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'cc:2**0': 0.24; "i've": 0.25; 'defined': 0.27; 'header:In-Reply- To:1': 0.27; 'point': 0.28; 'function': 0.29; 'chris': 0.29; 'external': 0.29; 'am,': 0.29; 'properties': 0.29; "i'm": 0.30; 'code': 0.31; 'too.': 0.31; 'dramatic': 0.31; 'class': 0.32; 'stuff': 0.32; 'supposed': 0.32; 'url:python': 0.33; 'sense': 0.34; 'but': 0.35; 'subject:?': 0.36; 'url:org': 0.36; 'so,': 0.37; 'too': 0.37; 'thank': 0.38; 'how': 0.40; 'skip:u 10': 0.60; 'no.': 0.61; 'url:3': 0.61; 'july': 0.63; 'refer': 0.63; 'default': 0.69; 'special': 0.74; 'behavior': 0.77; 'subject:this': 0.83; 'url:reference': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=simple/simple; d=nottheoilrig.com; s=mail; t=1373988335; bh=Xmzsq1TJGuvjfjB+7HQEdhUcZOnc5M6L8YpGvqP2znA=; h=Message-ID:Date:From:MIME-Version:To:CC:Subject:References: In-Reply-To:Content-Type:Content-Transfer-Encoding; b=JqK3Qek9mnOIC6aLyN7n6NUAWfTXNePxTSkWNl7TCggbK7YMIdvkT13nqgiOiPU14 xXahEgQfAfvNpkcEEi1xQqwwlAAsvuoWOexHGVoXfM+MQ5zIRwuZDhOGHukJdwOpkN wblCxPJ2eDOQXDcgtYBD0y4SJhsjwmp38p4YHW/U=
Date Tue, 16 Jul 2013 08:25:35 -0700
From Jack Bates <tdhfwh@nottheoilrig.com>
User-Agent Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130509 Thunderbird/17.0.6
MIME-Version 1.0
To Joshua Landau <joshua@landau.ws>
Subject Re: Is this a bug?
References <51E41A5C.7060903@nottheoilrig.com> <CAN1F8qUdqhkdROy22PBM+1Tq8Mxyg3PbbrdAQY1XOjXv7yF+QA@mail.gmail.com>
In-Reply-To <CAN1F8qUdqhkdROy22PBM+1Tq8Mxyg3PbbrdAQY1XOjXv7yF+QA@mail.gmail.com>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
Cc python-list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4773.1373988344.3114.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1373988344 news.xs4all.nl 15952 [2001:888:2000:d::a6]:60174
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:50745

Show key headers only | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web