[Python-Dev] Writable __doc__

Noufal Ibrahim noufal at nibrahim.net.in
Thu Jan 19 06:07:30 CET 2012


Sreenivas Reddy T <thatiparthysreenivas at gmail.com> writes:

> this is happening on python 2.6 too.
>
> Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
> [GCC 4.4.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> class Test(type):
> ...       __doc__=
>   File "<stdin>", line 2
>     __doc__=
>            ^
> SyntaxError: invalid syntax
>>>> class Test(type):
> ...       __doc__='asasdas'
> ...
>>>>


I don't get any syntax errors (Python2.7 and 2.6)

>>> class Test(object):
...   __doc__ = "Something"
... 
>>> 
>>> help(Test)

>>> class Test(type):
...   __doc__ = "something"
... 
>>> help(Test)

>>> Test.__doc__
'something'

>>>> Test.__doc__='sadfsdff'
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> AttributeError: attribute '__doc__' of 'type' objects is not writable
>>>> type(Test)
> <type 'type'>
>>>>

The __name__, __bases__, __module__, __abstractmethods__, __dict__ and
__doc__ attributes have custom getters and setters in the type object
definition. __doc__ has only a getter. No setter and no deleter.

http://hg.python.org/cpython/file/0b5ce36a7a24/Objects/typeobject.c#l658

That is why you're seeing this. What's the question here?

[...]


-- 
~noufal
http://nibrahim.net.in

May I ask a question?


More information about the Python-Dev mailing list