【问题标题】:Documenting user created type declarations with Sphinx使用 Sphinx 记录用户创建的类型声明
【发布时间】:2022-11-21 22:55:59
【问题描述】:

我正在做一个类型声明。例如:

from typing import Tuple
Type1 = Tuple[str, float]

我希望 Sphinx 像函数声明一样记录此声明。我怎样才能做到这一点?提前致谢。

如果我制作文档并添加通常的描述,结果是这些类型的声明显示为纯文本,而不是特殊的东西。

【问题讨论】:

    标签: python-sphinx


    【解决方案1】:

    一种规范的 Python 方法是使用 PEP-653 中的 TypeAlias

    #: Funny type that is mixing strings and floats - sounds like JavaScript programming!
    Type1: TypeAlias = Tuple[str, float]
    

    它是在 Python 3.10 中添加的。

    在撰写本文时,自动生成文档的 Sphinx 组件,autodoc,does not support TypeAlias yet

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-18
      • 2021-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多