继承时更改文档字符串但保留方法相同

Change docstring when inheriting but leave method the same

我正在构建一个 HTTP API 并且我将大量代码分解为一个 superclass 来处理对对象集合的请求。在我的 subclass 中,我指定操作应该在哪些数据库模型上工作,而 superclass 负责其余的工作。

这意味着我不需要重新实现 superclass 中的 get、post 等方法,但是,我想在 subclass 这样我就可以获得一些更具体到端点所运行的实际模型的文档。

继承父 class 功能但更改文档字符串的最简洁方法是什么?

示例:

class CollectionApi(Resource):
    """Operate on a collection of something.
    """
    class Meta(object):
        model = None
        schema = None


    def get(self):
        """Return a list of collections.
        """
        # snip

    def post(self):
        """Create a new item in this collection.
        """
        # snip

class ActivityListApi(CollectionApi):
    """Operations on the collection of Activities.
    """
    class Meta(object):
        model = models.Activity
        schema = schemas.ActivitySchema

具体来说,我需要 ActivityListApigetpost 运行 就像在 CollectionApi 中一样,但我想要不同的文档字符串(为了自动文档的缘故).

我能做到:

    def get(self):
        """More detailed docs
        """
        return super(ActivityListApi, self).get()

但这看起来很乱。

class CollectionApi(Resource):
    """Operate on a collection of something.
    """

    def _get(self):
        """actual work... lotsa techy doc here!

           the get methods only serve to have something to hang 
           their user docstrings onto
        """

        pass

    def get(self):
        """user-intended doc for CollectionApi"""
        return self._get()

class ActivityListApi(CollectionApi):

    def get(self):
        """user-intended doc for ActivityListApi"""
        return self._get()