Message111488
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. |
|
Date |
User |
Action |
Args |
2010-07-24 15:23:22 | gvanrossum | set | recipients:
+ gvanrossum, terry.reedy, mark.dickinson, eric.smith, benjamin.peterson, eric.araujo, r.david.murray, monsanto |
2010-07-24 15:23:22 | gvanrossum | set | messageid: <1279985002.48.0.77449355531.issue9226@psf.upfronthosting.co.za> |
2010-07-24 15:23:20 | gvanrossum | link | issue9226 messages |
2010-07-24 15:23:19 | gvanrossum | create | |
|