surprising interaction between function scope and class namespace

2011-08-15 Thread Stefan Behnel
Hi, I just stumbled over this: A = 1 def foo(x): ... A = x ... class X: ... a = A ... return X ... foo(2).a 2 def foo(x): ... A = x ... class X: ... A = A ... return X ... foo(2).A 1 Works that way in Py2.7 and

Re: surprising interaction between function scope and class namespace

2011-08-15 Thread Stefan Behnel
Stefan Behnel, 15.08.2011 11:33: I just stumbled over this: A = 1 def foo(x): ... A = x ... class X: ... a = A ... return X ... foo(2).a 2 def foo(x): ... A = x ... class X: ... A = A ... return X ... foo(2).A 1 Works that way in

Re: surprising interaction between function scope and class namespace

2011-08-15 Thread Duncan Booth
Stefan Behnel stefan...@behnel.de wrote: I couldn't find any documentation on this, but my *guess* about the reasoning is that the second case contains an assignment to A inside of the class namespace, and assignments make a variable local to a scope, in this case, the function scope.

Re: surprising interaction between function scope and class namespace

2011-08-15 Thread Peter Otten
Stefan Behnel wrote: Hi, I just stumbled over this: A = 1 def foo(x): ... A = x ... class X: ... a = A ... return X ... foo(2).a 2 def foo(x): ... A = x ... class X: ... A = A ... return X

Re: surprising interaction between function scope and class namespace

2011-08-15 Thread Gregory Ewing
Peter Otten wrote: LOAD_NAME is pretty dumb, it looks into the local namespace and if that lookup fails falls back to the global namespace. Someone probably thought I can do better, and reused the static name lookup for nested functions for names that occur only on the right-hand side of