【问题标题】:How to get Sphinx to use type annotations from Python stub files如何让 Sphinx 使用 Python 存根文件中的类型注释
【发布时间】:2021-09-05 19:16:13
【问题描述】:

我使用存根文件(即“*.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 annotations python-sphinx stub python-typing


【解决方案1】:

我使用存根文件是因为我想避免我的 Python 源文件中包含类型信息。但是,(目前)最简单的解决方案似乎是将类型信息放入源文件并取消存根文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-01
    • 2018-08-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-09
    • 2017-06-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多