python-sphinxdocstringsphinx-napoleon

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


I am using Sphinx 4.4.0 with napoleon extension (Google Doc String). I have this two problems

I found something about it on the internet but can not fit this two my code. My problem is I even do not understand the messages. I do not see where the problem could be.

This is the code:

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.

    """

This are the original messages:

.../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.

Solution

  • reStructuredText is not Markdown, and indentation alone is not enough to demarcate the code block. reStructuredText calls this a 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.

    Also I noticed that you have invalid syntax in your code block—a missing ) and extra spaces in your indentation—which could have caused those errors.

    Try this.

    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.
    
        """