【问题标题】:Sphinx autodoc mock imports results in undocumented objectSphinx autodoc 模拟导入导致未记录的对象
【发布时间】:2021-12-29 05:10:12
【问题描述】:

我正在尝试记录从模拟导入 (foo.FOO) 派生的常量

foo.py

"""Foo module."""


from asdf import qwerty


FOO = qwerty.FOO
"""Foo constant."""


ASDF = 1
"""ASDF."""


def foo():
    """Return foo :py:const:`foo.FOO` :py:const:`foo.ASDF`."""
    return FOO

conf.py

import os
import sys
sys.path.insert(0, os.path.abspath(os.pardir))

project = 'sphinx'
copyright = '2021, sphinx'
author = 'sphinx'

extensions = ['sphinx.ext.autodoc']
templates_path = ['_templates']
exclude_patterns = []
html_theme = 'alabaster'
html_static_path = ['_static']

autodoc_mock_imports = ['asdf']
nitpicky = True

#nitpick_ignore = [
#    ('py:class', 'foo.FOO'),
#]

当我运行 make html SPHINXOPTS=-Ea 时,我得到了生成的文档。

但我希望当我模拟 foo.FOO 记录的导入时(见上图)。

狮身人面像:4.3.0

这是功能还是错误?

【问题讨论】:

  • 我可以重现该问题。一种解决方法是在 foo.py 中添加 FOO.__doc__ = "Foo constant."
  • 谢谢,但在那种情况下,我怀疑它真的是一个狮身人面像的错误。
  • 是的,谢谢,我看到了,但由于它尚未发布,我无法对其进行测试。
  • @mzjn 如果这是一个错误,你知道如何处理这个问题吗?关闭、删除、解决,...?

标签: python mocking python-sphinx autodoc


【解决方案1】:

这实际上是一个错误并已修复https://github.com/sphinx-doc/sphinx/pull/9905

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-06
    • 2016-07-24
    • 1970-01-01
    • 2015-02-04
    • 1970-01-01
    • 2016-12-17
    • 1970-01-01
    相关资源
    最近更新 更多