Terry J. Reedy <tjre...@udel.edu> added the comment: Chris, when posting something like this, *please* include the output. I had to insert ()s to run this with 3.1. I will upload the py3 version as test3.py. Is your output the same as mine?
x: success Test.x: error Test2.y: success Test3.x: error Test3.y: error Test4.x: success There is an obvious inconsistency between Test2 and Test/Test3. This shows up also in the dis.dis(test) output. So there is definitely a bug. To me, the Test2 result is the error. I base this on 7.7 Class Definitions: "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." I interpret this to mean that intermediate namespaces are not used (as was the case before 2.2). Indeed, this sentence is unchanged from the 2.1 doc (and before). http://docs.python.org/release/2.1/ref/class.html Of course, the intent could have changed without changing the wording, by reference to the Naming and Binding section, but then this sentence really should be changed too. The current Naming and Binding section includes: "A scope defines the visibility of a name within a block. If a local variable is defined in a block, its scope includes that block. If the definition occurs in a function block, the scope extends to any blocks contained within the defining one, unless a contained block introduces a different binding for the name. The scope of names defined in a class block is limited to the class block; it does not extend to the code blocks of methods." So class blocks are an exception in propagating down, and I thought they were also an exception for propagating into, for the reason stated above. It is possible that this is an undefined corner of the language. Certainly, the compiler is confused as it treats one nested class (Test2) as a closure and the other three nested classes as not. Since the name and binding design is Guido's and central to Python's operation, I personally would not touch it without his input. Hence I have added him as nosy and second the idea of pydev discussion. ---------- nosy: +gvanrossum, tjreedy Added file: http://bugs.python.org/file18164/test3.py _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue9226> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com