[Python-Dev] readonly __doc__

Daniel Fetchinson fetchinson at googlemail.com
Thu Oct 22 19:00:51 CEST 2009


> Speaking of the __doc__ property, I just noticed the following thing on
> py3k:
>
>>>> class C: pass
> ...
>>>> C.__doc__ = "hop"
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> AttributeError: attribute '__doc__' of 'type' objects is not writable

Happens also with new style classes in python 2.x:

Python 2.5.1 (r251:54863, Oct 30 2007, 13:45:26)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class C(object): pass
...
>>> C.__doc__ = 'hello'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: attribute '__doc__' of 'type' objects is not writable
>>>


But not with old style classes:


Python 2.5.1 (r251:54863, Oct 30 2007, 13:45:26)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class C: pass
...
>>> C.__doc__ = 'hello'
>>>

Cheers,
Daniel

-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown


More information about the Python-Dev mailing list