代码之家  ›  专栏  ›  技术社区  ›  aerin

在python注释中,冒号包装的类是什么意思?

  •  1
  • aerin  · 技术社区  · 6 年前

    什么是冒号包装类( :class: )python注释中的意思?

    例如,

    class Optimizer(object):
        r"""Base class for all optimizers.
        Arguments:
            params (iterable): an iterable of :class:`torch.Tensor` s or
                :class:`dict` s. Specifies what Tensors should be optimized.
            defaults: (dict): a dict containing default values of optimization
                options (used when a parameter group doesn't specify them).
        """
    
        def __init__(self, params, defaults):
            self.defaults = defaults
    

    它是pytorch特定的语法,还是什么?

    资料来源: https://github.com/pytorch/pytorch/blob/master/torch/optim/optimizer.py

    1 回复  |  直到 6 年前
        1
  •  6
  •   Martijn Pieters    6 年前

    这不是python或torch特有的。它是文档工具的语法;很可能 Sphinx 是的。

    语法表示对另一个类的文档的交叉引用。当文档工具生成超链接输出(如HTML)时,此类引用将自动成为指向命名类的文档页的链接。

    对于狮身人面像,请参见 Cross-referencing syntax documentation ;你会看到 py:class: 作为类引用,但是我们可以假设默认域设置为python,所以 :class: 也是有效的。

    确实是火把计划 uses Sphinx to generate the documenation 是的。你可以比较你找到的来源 the resulting generated documenation ;请注意 dict torch.Tensor 是指向更多文档的超链接。