如何告诉 "where class definition of forward reference in type hints is" 给 Sphinx?
How to tell "where class definition of forward reference in type hints is" to Sphinx?
如何告诉 "where class definition of forward reference in type hints is" 给 Sphinx?
如何避免丢失参数(在 Sphinx 文档中),其类型由类型提示的前向引用定义?
我使用 sphinx-apidoc 编写我的 Python 程序的文档。
我正在使用 PEP 484 中定义的类型提示的前向引用,如下所示:
# In file A/A.py
class A:
def a(self, param: 'MyClass') -> None:
"""docstring here"""
pass
不导入MyClass以避免循环导入。当然,该程序运行良好,因为类型提示在 运行 时被忽略。
当我运行 sphinx-apidoc 并生成html 时,出现以下警告(未定义名称'MyClass')。
$ sphinx-apidoc -f -o doc .
Creating file doc/A.rst
$ make html
...
reading sources... [100%] main
path/to/A/A.rst:XX: WARNING: error while formatting arguments for A.A.a: name 'MyClass' is not defined
looking for now-outdated files... none found
...
build succeeded, 1 warnings.
Build finished. The HTML pages are in _build/html.
在生成的html中,方法'a'没有这样的参数:
A module
class A
a() -> None
docstring here
在导入 MyClass 的上下文中(没有循环导入),生成的 html 具有如下参数:
A module
class A
a(param: MyClass) -> None
docstring here
我的环境:
$ python3 --version
Python 3.5.2
$ pip3 --version
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)
$ pip3 freeze | grep Sphinx
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Sphinx==1.5.2
根据 sphinx 问题跟踪器,他们在 sphinx 1.6 上修复了这个问题。也许试试那个版本。我从来没有尝试过,所以这只是一个建议。
如何告诉 "where class definition of forward reference in type hints is" 给 Sphinx?
如何避免丢失参数(在 Sphinx 文档中),其类型由类型提示的前向引用定义?
我使用 sphinx-apidoc 编写我的 Python 程序的文档。
我正在使用 PEP 484 中定义的类型提示的前向引用,如下所示:
# In file A/A.py
class A:
def a(self, param: 'MyClass') -> None:
"""docstring here"""
pass
不导入MyClass以避免循环导入。当然,该程序运行良好,因为类型提示在 运行 时被忽略。
当我运行 sphinx-apidoc 并生成html 时,出现以下警告(未定义名称'MyClass')。
$ sphinx-apidoc -f -o doc .
Creating file doc/A.rst
$ make html
...
reading sources... [100%] main
path/to/A/A.rst:XX: WARNING: error while formatting arguments for A.A.a: name 'MyClass' is not defined
looking for now-outdated files... none found
...
build succeeded, 1 warnings.
Build finished. The HTML pages are in _build/html.
在生成的html中,方法'a'没有这样的参数:
A module
class A
a() -> None
docstring here
在导入 MyClass 的上下文中(没有循环导入),生成的 html 具有如下参数:
A module
class A
a(param: MyClass) -> None
docstring here
我的环境:
$ python3 --version
Python 3.5.2
$ pip3 --version
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)
$ pip3 freeze | grep Sphinx
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Sphinx==1.5.2
根据 sphinx 问题跟踪器,他们在 sphinx 1.6 上修复了这个问题。也许试试那个版本。我从来没有尝试过,所以这只是一个建议。