sphinx autodoc-skip-member handler:使用拿破仑时无法显示__init __()

时间:2016-03-28 20:14:05

标签: python python-sphinx

我想在我的sphinx生成的文档中包含__init__()的文档字符串。

我正在关注the accepted answer to this stackoverflow questionautodoc-skip-member添加处理程序,但仍无法查看我的__init__()文档。 if name == "__init__":块中的跟踪代码显示我正在访问该代码。

在预感中,我从'sphinx.ext.napoleon'定义中删除了extensions,留下了

extensions = [
    'sphinx.ext.autodoc',
    # 'sphinx.ext.napoleon',
]

然后我可以看到__init__()文档。

我在the napoleon documentation中看到的与napoleon_include_special_with_doc相关的唯一内容是True,默认为True。 <{1}}中明确将其设置为conf.py似乎没有任何改变。

ETA:如果我添加以下方法:

def __blah__(self):
    '''blah blah blah'''
    print self.__class__

我在生成的文档中看到了__blah__()

  • 如果我将__blah__的名称更改为__repr____str__, 我在生成的文档中看到了它们。
  • 如果我注释掉现有的__init__并进行更改 __blah____init__我看不到它。

所以它似乎特定于__init__()

这是一个已知的问题,还有另一种方法可以控制使用拿破仑吗?

2 个答案:

答案 0 :(得分:0)

拿破仑遵循您的autodoc配置,了解您希望如何处理__init__方法。

检查conf.py中的autodoc设置。请务必确保将autoclass_content设置为initboth

答案 1 :(得分:0)

Per Rob在https://github.com/sphinx-doc/sphinx/issues/2374的跟随,如果您正在使用任何也为“autodoc-skip-member”事件设置处理程序的扩展,则只会使用其中一个处理程序。这似乎是手头的问题。谢谢Rob!