简体   繁体   English

sphinx autodoc-skip-member 处理程序:使用拿破仑时无法显示 __init__()

[英]sphinx autodoc-skip-member handler: can't show __init__() when using napoleon

I want to include the docstrings for __init__() in my sphinx-generated documentation.我想在我的 sphinx 生成的文档中包含__init__()的文档字符串。

I was following the accepted answer to this stackoverflow question to add a handler for autodoc-skip-member and was still unable to see my __init__() documentation.我正在按照这个 stackoverflow 问题的公认答案autodoc-skip-member添加一个处理程序, autodoc-skip-member仍然无法看到我的__init__()文档。 Trace code inside the if name == "__init__": block shows I am hitting that code. if name == "__init__":块中的跟踪代码显示我正在点击该代码。

On a hunch I removed 'sphinx.ext.napoleon' from my extensions definition, leaving 'sphinx.ext.napoleon'直觉,我从extensions定义中删除了'sphinx.ext.napoleon' ,留下

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

and then I can see the __init__() documentation.然后我可以看到__init__()文档。

The only thing I see in the napoleon documentation that seems relevant is napoleon_include_special_with_doc , which it says defaults to True .我在拿破仑文档中看到的唯一似乎相关的是napoleon_include_special_with_doc ,它说默认为True Explicitly setting it to True in conf.py doesn't seem to change anything.conf.py其显式设置为True似乎没有任何改变。

ETA: If I add the following method: ETA:如果我添加以下方法:

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

I see __blah__() in my generated documentation.我在生成的文档中看到__blah__()

  • If I change the name of __blah__ to __repr__ or __str__ , I see them in the generated documentation.如果我将__blah__的名称__blah____repr____str__ ,我会在生成的文档中看到它们。
  • If I comment out the existing __init__ and change __blah__ to __init__ I don't see it.如果我注释掉现有的__init__并将__blah__更改为__init__我看不到它。

So it seems specific to __init__() .所以它似乎特定于__init__()

Is this a known issue, and is there another way to control this when using napoleon?这是一个已知问题,在使用拿破仑时是否有另一种方法来控制这个问题?

Napoleon defers to your autodoc configuration for how you want to handle the __init__ method. Napoleon 遵循您的 autodoc 配置,以了解您希望如何处理__init__方法。

Check your autodoc settings in conf.py .检查你的车博士设置conf.py In particular, make sure autoclass_content is set to either init or both .特别是,确保autoclass_content设置为initboth

Per Rob's followon at https://github.com/sphinx-doc/sphinx/issues/2374 , if you're using any extension that also sets a handler for the "autodoc-skip-member" event only one of the handlers will be used. Per Rob 在https://github.com/sphinx-doc/sphinx/issues/2374的后续,如果您使用的任何扩展也为“autodoc-skip-member”事件设置处理程序,则只有一个处理程序会被使用。 This would seem to be the issue at hand.这似乎是手头的问题。 Thanks Rob!谢谢罗布!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM