[Python-ideas] inheriting docstrings and mutable docstings for classes
ericsnowcurrently at gmail.com
Fri Jun 10 01:54:14 CEST 2011
I noticed that __doc__ for classes is immutable:
>>> class X:
... "some doc"
>>> X.__doc__ = "another doc"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: attribute '__doc__' of 'type' objects is not writable
That is on 3.3, but apparently it's the case all the way back to 2.2.
I mentioned this on python-list and several people indicated that it
should be an unnecessary restriction . Someone else pointed out
that docstrings also behave this way for method objects .
I want too see if it would be okay to make __doc__ writable for
classes. I am not sure about for method objects, since I've never
thought to do that, but it is analogous to class instances, where
__doc__ is mutable and distinct from the class docstring. I just
don't have any use cases that would dictate changing the docstring of
the method object, the wrapped function, or neither when changing
Someone else on the thread indicated that perhaps docstrings should be
inherited and got some support . It makes sense to me for many,
but not necessarily all, cases. However, if you don't want to inherit
you can simply set an empty docstring. Docstrings impact help(),
doctests, and some DSLs. I'm +1 on having __doc__ be inherited.
More information about the Python-ideas