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 monsanto
Recipients monsanto
Date 2010-07-11.19:56:33
SpamBayes Score 0.0004110877
Marked as misclassified No
Message-id <1278878196.2.0.124754685152.issue9226@psf.upfronthosting.co.za>
In-reply-to
Content
I have a function whose closure contains a local variable that shadows a global variable (lets call it x). If I create a class as follows: 

class Test(object): x = x

Test.x will contain the value of the global x, not the local x. This ONLY happens when the names are the same, and it only happens in the class body; i.e., "class Test(object): y = x" and class "Test(object): pass; Test.x = x" work fine.

However, if there is an assignment x = x AND you make other assignments, such as y = x, in the body, the other variables will have the wrong value too.

Test case attached. Problem noticed on Python 2.6.2 on Windows and 2.6.5 on Linux.
History
Date User Action Args
2010-07-11 19:56:36monsantosetrecipients: + monsanto
2010-07-11 19:56:36monsantosetmessageid: <1278878196.2.0.124754685152.issue9226@psf.upfronthosting.co.za>
2010-07-11 19:56:34monsantolinkissue9226 messages
2010-07-11 19:56:34monsantocreate