Terry J. Reedy <tjre...@udel.edu> added the comment:

This is not a bug report, as Python works as documented. 
Double underscore names are defined as *reserved* for the interpreter, with the 
ones actually in use having defined meanings.

type.__new__ sets several internally used attributes on new classes. The 
attribute look-up mechanism for classes looks at them first before looking in 
__dict__, which is for attributes of both the class and its instances. Here is 
another example similar to yours.

>>> class C: __dict__ = 1

>>> C.__dict__
dict_proxy({'__dict__': 1, '__module__': '__main__', '__weakref__': <attribute 
'__weakref__' of 'C' objects>, '__doc__': None})
>>> C().__dict__
1

__dict__ is not writable, but __class__ is. You can already rename a class if 
you really want:

>>> C.__name__ = 'bizarre'
>>> C.__name__
'bizarre'

Conceptually, this seems the right way as one normally would not want the name 
of the class to be the default name for every instance.

>>> C().__name__
Traceback (most recent call last):
  File "<pyshell#12>", line 1, in <module>
    C().__name__
AttributeError: 'bizarre' object has no attribute '__name__'

If you really want instances to have that also, then also do as you did.

There are other class-only, not for instances, attributes:
__mro__ and __subclasses__ and perhaps others.

----------
nosy: +terry.reedy
resolution:  -> rejected
status: open -> closed
type: behavior -> enhancement
versions:  -Python 2.6, Python 2.7, Python 3.1, Python 3.2

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

Reply via email to