how to inherit docstrings?
Ben Finney
ben+python at benfinney.id.au
Thu Jun 9 02:37:39 EDT 2011
Eric Snow <ericsnowcurrently at gmail.com> writes:
> p.s. Am I missing something or can you really not change the docstring
> of a class? I was thinking about the idea of inheriting class
> docstrings too.
The docstring of an object (whether function or class or module) is the
object's ‘__doc__’ attribute. Access that attribute to get the
docstring; re-bind that attribute to set a different docstring.
So, it's even possible to do what you ask without decorators at all:
class Foo(object):
def frob(self):
""" Frobnicate thyself. """
class Bar(Foo):
def frob(self):
pass
frob.__doc__ = Foo.frob.__doc__
Not very elegant, and involving rather too much repetition; but not
difficult.
--
\ “We are no more free to believe whatever we want about God than |
`\ we are free to adopt unjustified beliefs about science or |
_o__) history […].” —Sam Harris, _The End of Faith_, 2004 |
Ben Finney
More information about the Python-list
mailing list