This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gvanrossum
Recipients benjamin.peterson, eric.araujo, eric.smith, gvanrossum, mark.dickinson, monsanto, r.david.murray, terry.reedy
Date 2010-07-24.23:10:09
SpamBayes Score 0.0008076366
Marked as misclassified No
Message-id <AANLkTika93=tAjxfQfSt70sm0HjArnJR+s7LG+sUUPbZ@mail.gmail.com>
In-reply-to <1280010093.66.0.525907822617.issue9226@psf.upfronthosting.co.za>
Content
On Sat, Jul 24, 2010 at 3:21 PM, Terry J. Reedy <report@bugs.python.org> wrote:
>
> Terry J. Reedy <tjreedy@udel.edu> added the comment:
>
> Guido clarified:
>> Class scopes *do* behave differently from function scopes;
>> outside a nested function, this should work:
>> x = 1
>> class C(object):
>>   x = x
>> assert C.x == 1
>> And I think it should work that way inside a function too.
>
> I take that to mean that
>
> x = 0
> def f()
>  x = 1
>  class C(object):
>    x = x
>  assert C.x == 1
> f()
>
> should work, meaning that C.x==0 and UnboundLocalError are both wrong.

Indeed.

> That would mean to me that in "The class’s suite is then executed in a new execution frame (see section Naming and binding), using a newly created local namespace and the original global namespace." the phrase "the original global namespace" should be changed to "the surrounding namespaces".

Those words sound like they were never revised since I wrote them for
Python 0.9.8 or so...

> I also think this from Guido
>
> "So, while for *function scopes* the rules are "if it is assigned anywhere in the function, every reference to it references the local version", for *class scopes* (outsided methods) the lookup rules are meant to be dynamic, meaning "if it isn't defined locally yet at the point of reference, use the next outer definition"."
>
> should somehow also be clearer, probably also in the class page, so that people will neither expect an UnboundLocalError.

FWIW, unless something drastically changed recently, the language
reference is likely out of date in many areas. I would love it if a
team of anal retentive freaks started going through it with a fine
comb so as to make it describe the state of the implementation(s) more
completely.
History
Date User Action Args
2010-07-24 23:10:12gvanrossumsetrecipients: + gvanrossum, terry.reedy, mark.dickinson, eric.smith, benjamin.peterson, eric.araujo, r.david.murray, monsanto
2010-07-24 23:10:10gvanrossumlinkissue9226 messages
2010-07-24 23:10:09gvanrossumcreate