how to inherit docstrings?

Eric Snow ericsnowcurrently at gmail.com
Thu Jun 9 02:22:54 EDT 2011


Sometimes when using class inheritance, I want the overriding methods
of the subclass to get the docstring of the matching method in the
base class.  You can do this with decorators (after the class
definition), with class decorators, and with metaclasses [1].

However, I was hoping for a way to do it with just function decorators
on the methods (no metaclass or class decorator).  I am not sure if
this is doable.  I realize now that this is exactly the reason I got
to thinking last week about objects being notified when they are bound
[2].

So, is there a way to do this with just decorators, or am I "stuck"
with the metaclass/class decorator route?  (It's not all that bad :)

Thanks!

-eric


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.


[1] http://code.activestate.com/recipes/577743-using-decorators-to-inherit-function-docstrings/
[2] http://mail.python.org/pipermail/python-ideas/2011-June/010446.html



More information about the Python-list mailing list