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.15:23:19
SpamBayes Score 0.00013206067
Marked as misclassified No
Message-id <1279985002.48.0.77449355531.issue9226@psf.upfronthosting.co.za>
In-reply-to
Content
Hm. This seems an old bug, probably introduced when closures where first introduced (2.1 ISTR, by Jeremy Hylton).

Class scopes *do* behave differently from function scopes; outside a nested function, this should work:

x = 1
class C(object):
  x = x
assert X.x == 1

And I think it should work that way inside a function too.

So IMO the bug is that in classes Test and Test3, the x defined in the function scope is not used.  Test2 shows that normally, the x defined in the inner scope is accessed.

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

I haven't reviewed the patches.
History
Date User Action Args
2010-07-24 15:23:22gvanrossumsetrecipients: + gvanrossum, terry.reedy, mark.dickinson, eric.smith, benjamin.peterson, eric.araujo, r.david.murray, monsanto
2010-07-24 15:23:22gvanrossumsetmessageid: <1279985002.48.0.77449355531.issue9226@psf.upfronthosting.co.za>
2010-07-24 15:23:20gvanrossumlinkissue9226 messages
2010-07-24 15:23:19gvanrossumcreate