相关疑难解决方法(0)

Python-Sphinx:来自超类的"继承"方法文档

编辑: 截至目前(Sphinx 1.4.9)似乎没有办法告诉Sphinx做我想做的事(参见GitHub上的问题).该接受的答案,从布莱希特Machiels解决以其他方式问题,直到狮身人面像可能是能够做到一天.

描述: 我正在尝试使用sphinx-apidoc记录Python项目.Sphinx配置几乎是默认的,我只是包括在内'sphinx.ext.autodoc'.

它一般工作,但派生类不会像我期望的那样继承其超类的方法文档.

示例: 考虑一个非常简约的Python包project.除了空__init__.py,它只包含一个文件(base.py见下文)

# -*- coding: utf-8 -*
import abc


class Superclass(object):
    """The one to rule them all"""

    @abc.abstractmethod
    def give(self, ring):
        """Give out a ring"""
        pass


class Derived(Superclass):
    """Somebody has to do the work"""

    def give(self, ring):
        print("I pass the ring {} to you".format(ring))
Run Code Online (Sandbox Code Playgroud)

运行sphinx-apidoc(sphinx-apidoc -o apidoc project -f)会生成以下文件:

python python-sphinx

5
推荐指数
1
解决办法
2032
查看次数

有没有办法让类继承sphinx的超类文档?

假设我有一堂课

class A(object):
  def myfunction():
    """A."""
    pass
Run Code Online (Sandbox Code Playgroud)

和一个子类

class B(A):
  def myfunction():
    pass
Run Code Online (Sandbox Code Playgroud)

是否可以使用sphinx从A.myfunction继承B.myfunction的API文档?B.myfunction的文档应为"A".同样.

python python-sphinx

4
推荐指数
1
解决办法
1375
查看次数

标签 统计

python ×2

python-sphinx ×2