Подтвердить что ты не робот

Как я должен записывать списки, опции и уроки, используя Sphinx в стиле Google?

Как указать типы списков, необязательные аргументы и типы возвращаемых данных для генераторов в докстронах в стиле Google с использованием Sphinx-Napoleon?

Я пробовал

List[type]
list of type

Optional[type]
type, optional

и

Yields:
   type: 

соответственно; но все они создают неудовлетворительный результат, который не согласуется с остальной частью сгенерированной документации. Например

Optional[type]

просто дает

Необязательный [тип]

без ссылки для type.

Я пробовал каждую встроенную тему и имел те же проблемы.

Как я должен документировать эти элементы, используя docstrings в стиле Google с Sphinx-Napoleon?

4b9b3361

Ответ 1

Я знаю, что это довольно старо, но вы посмотрели этот пример? В частности, строки:

def __init__(self, param1, param2, param3):
        """Example of docstring on the __init__ method.

        The __init__ method may be documented in either the class level
        docstring, or as a docstring on the __init__ method itself.

        Either form is acceptable, but the two should not be mixed. Choose one
        convention to document the __init__ method and be consistent with it.

        Note:
            Do not include the `self` parameter in the ``Args`` section.

        Args:
            param1 (str): Description of `param1`.
            param2 (:obj:`int`, optional): Description of `param2`. Multiple
                lines are supported.
            param3 (:obj:`list` of :obj:`str`): Description of `param3`.

        """
        self.attr1 = param1
        self.attr2 = param2
        self.attr3 = param3  #: Doc comment *inline* with attribute

        #: list of str: Doc comment *before* attribute, with type specified
        self.attr4 = ['attr4']

        self.attr5 = None
        """str: Docstring *after* attribute, with type specified."""