New submission from Chris Monsanto <ch...@monsan.to>:

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.

----------
files: test.py
messages: 110037
nosy: monsanto
priority: normal
severity: normal
status: open
title: erroneous behavior when creating classes inside a closure
versions: Python 2.6
Added file: http://bugs.python.org/file17950/test.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

Reply via email to