Nick Coghlan added the comment:

Carsten: emulating __class__ is necessary to implement proxy types (and similar 
utilities like mock objects) correctly. The difference between "x.__class__" is 
that proxies can remap it to the type of the referent, while "type(x)" will 
always report the real class of "x" (which may be a proxy like weakref.proxy, 
or a mock object, as it is in the case Michael is interested in).

Mark: correct, the problem is that the compiler is treating *all* references to 
__class__ inside a class body as references to the cell variable, when it 
should really only be doing that for references inside methods - references 
directly at the class body level should still be to the entry in the class 
locals namespace that later become attributes of the class object. Hence my 
idea of introducing a separate closure namespace encapsulating the class 
namespace to separate the two more cleanly than the current hacky override.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue12370>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to