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, eukreign, terry.reedy
Date 2012-02-25.01:15:31
SpamBayes Score 6.933343e-14
Marked as misclassified No
Message-id <1330132532.65.0.71379131172.issue14092@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2012-02-25 01:15:32terry.reedysetrecipients: + terry.reedy, benjamin.peterson, eukreign
2012-02-25 01:15:32terry.reedysetmessageid: <1330132532.65.0.71379131172.issue14092@psf.upfronthosting.co.za>
2012-02-25 01:15:32terry.reedylinkissue14092 messages
2012-02-25 01:15:31terry.reedycreate