Sphinx-autodoc with napoleon (Google Doc String Style):关于块引号和缩进的警告和错误

Sphinx-autodoc with napoleon (Google Doc String Style): Warnings and Errors about Block quotes and indention

我正在使用带有拿破仑扩展名的 Sphinx 4.4.0(Google 文档字符串)。我有这两个问题

我在网上找到了一些关于它的东西,但我的代码不适合这两个。我的问题是我什至不理解消息。我看不出问题出在哪里。

这是代码:

def read_and_validate_csv(basename, specs_and_rules):
    """Read a CSV file with respect to specifications about format and
    rules about valid values.

    Hints: Do not use objects of type type (e.g. str instead of "str") when
    specificing the column type.

        specs_and_rules = {
            'TEMPLATES': {
                 'T1l': ('Int16', [-9, ' '])
                 },
             'ColumnA': 'str',
             'ColumnB': ('str', 'no answer'),
             'ColumnC': None,
             'ColumnD': (
                 'Int16',
                 -9, {
                     'len': [1, 2, (4-8)],
                     'val': [0, 1, (3-9)]
                 }
             }

    Returns:
        (pandas.DataFrame): Result.

    """

这是原始消息:

.../bandas.py:docstring of buhtzology.bandas.read_and_validate_csv:11: WARNING: Block quote ends without a blank line; unexpected unindent.
.../bandas.py:docstring of buhtzology.bandas.read_and_validate_csv:15: ERROR: Unexpected indentation.
.../bandas.py:docstring of buhtzology.bandas.read_and_validate_csv:17: ERROR: Unexpected indentation.
.../bandas.py:docstring of buhtzology.bandas.read_and_validate_csv:19: WARNING: Block quote ends without a blank line; unexpected unindent.
.../bandas.py:docstring of buhtzology.bandas.read_and_validate_csv:20: WARNING: Block quote ends without a blank line; unexpected unindent.

reStructuredText 不是 Markdown,仅靠缩进不足以划定代码块。 reStructuredText 称其为 literal block. Although the use of :: is one option, you might want to explicitly specify the language (overriding the default) with the use of the code-block directive.

我还注意到您的代码块中有无效语法——缺少 ) 和缩进中的额外空格——这可能导致了这些错误。

试试这个。

def read_and_validate_csv(basename, specs_and_rules):
    """Read a CSV file with respect to specifications about format and
    rules about valid values.

    Hints: Do not use objects of type type (e.g. str instead of "str") when
    specificing the column type.

    ..  code-block:: python

        specs_and_rules = {
            'TEMPLATES': {
                 'T1l': ('Int16', [-9, ' '])
                 },
            'ColumnA': 'str',
            'ColumnB': ('str', 'no answer'),
            'ColumnC': None,
            'ColumnD': (
                'Int16',
                -9, {
                    'len': [1, 2, (4-8)],
                    'val': [0, 1, (3-9)]
                }
            )
        }

    Returns:
        (pandas.DataFrame): Result.

    """