python - 如何让 Sphinx 使用 Python 存根文件中的类型注释
问题描述
我使用存根文件(即“*.pyi”文件)来管理项目中的类型注释。我的文档字符串在实际的源文件中。我已经安装sphinx-autodoc-annotation
了 Sphinx 来查看类型注释,但它不查看存根文件。通过 Sphinx 生成文档时,如何从存根文件中提取类型?
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
解决方案
我使用存根文件是因为我想避免 Python 源文件与类型信息混淆。然而,最简单的解决方案(目前)似乎是将类型信息放入源文件并取消存根文件。
推荐阅读
- javascript - 编译 ejs i18next 时出现意外的令牌
- c# - 如何增加 RemoteWebDriver 的 HTTP 请求超时
- python - 如何创建一个仅在满足某些条件时才发生实例化的类?
- javascript - 如何在 Bootstrap 的页面刷新时保持当前 Accordion 处于活动状态
- php - 无法从连接表中检索数据
- java - 值 1 和值 2 的偶数
- c++ - 标准库是否提供类型列表?
- javascript - 反应路由器记忆路由向导
- android - 使用 gradle 为带有风味的库上传存档
- linq - 如何使用 linq 遍历所有图像,但只搜索这些图像中字符串的一部分?