➜

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-23.21:08:34
SpamBayes Score 0.00014012164
Marked as misclassified No
Message-id <1279919317.21.0.892953400078.issue9226@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2010-07-23 21:08:37terry.reedysetrecipients: + terry.reedy, gvanrossum, mark.dickinson, eric.smith, benjamin.peterson, eric.araujo, r.david.murray, monsanto
2010-07-23 21:08:37terry.reedysetmessageid: <1279919317.21.0.892953400078.issue9226@psf.upfronthosting.co.za>
2010-07-23 21:08:35terry.reedylinkissue9226 messages
2010-07-23 21:08:34terry.reedycreate