def inherit_docstring_from(cls):
def _doc(func):<EOL><INDENT>cls_docstring = getattr(cls, func.__name__).__doc__<EOL>func_docstring = func.__doc__<EOL>if func_docstring is None:<EOL><INDENT>func.__doc__ = cls_docstring<EOL><DEDENT>else:<EOL><INDENT>new_docstring = func_docstring % dict(super=cls_docstring)<EOL>func.__doc__ = new_docstring<EOL><DEDENT>return func<EOL><DEDENT>return _doc<EOL>
This decorator modifies the decorated function's docstring by
replacing occurrences of '%(super)s' with the docstring of the
method of the same name from the class `cls`.

If the decorated method has no docstring, it is simply given the
docstring of `cls`s method.

Parameters
----------
cls : Python class or instance
    A class with a method with the same name as the decorated method.
    The docstring of the method in this class replaces '%(super)s' in the
    docstring of the decorated method.

Returns
-------
f : function
    The decorator function that modifies the __doc__ attribute
    of its argument.

Examples
--------
In the following, the docstring for Bar.func created using the
docstring of `Foo.func`.

>>> class Foo(object):
...     def func(self):
...         '''Do something useful.'''
...         return
...
>>> class Bar(Foo):
...     @inherit_docstring_from(Foo)
...     def func(self):
...         '''%(super)s
...         Do it fast.
...         '''
...         return
...
>>> b = Bar()
>>> b.func.__doc__
'Do something useful.\n        Do it fast.\n        '