我使用 stub 文件(即“*.pyi”文件)来管理我项目中的类型注释。我的文档字符串在实际的源文件中。我已经安装了 sphinx-autodoc-annotation
让 Sphinx 查看类型注释,但不查看 stub 文件。通过 Sphinx 生成文档时,如何从 stub 文件中提取类型?
foo.pyi
class Foo:
def bar(self, baz: str) -> str:
...
foo.py
class Foo:
def bar(self, baz):
"""Does some cool stuff
:param baz: some parameter that we do stuff with
"""
return baz
最佳答案
我使用 stub 文件是因为我想避免类型信息使我的 Python 源文件困惑。然而,最简单的解决方案(目前)似乎是无论如何都将类型信息放入源文件并取消 stub 文件。
关于python - 如何让 Sphinx 使用来自 Python stub 文件的类型注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68079405/