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 terry.reedy
Recipients benjamin.peterson, eric.araujo, eric.smith, gvanrossum, mark.dickinson, monsanto, r.david.murray, terry.reedy
Date 2010-07-24.22:21:31
SpamBayes Score 0.00035377147
Marked as misclassified No
Message-id <1280010093.66.0.525907822617.issue9226@psf.upfronthosting.co.za>
In-reply-to
Content
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.

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".

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.
History
Date User Action Args
2010-07-24 22:21:33terry.reedysetrecipients: + terry.reedy, gvanrossum, mark.dickinson, eric.smith, benjamin.peterson, eric.araujo, r.david.murray, monsanto
2010-07-24 22:21:33terry.reedysetmessageid: <1280010093.66.0.525907822617.issue9226@psf.upfronthosting.co.za>
2010-07-24 22:21:32terry.reedylinkissue9226 messages
2010-07-24 22:21:31terry.reedycreate