Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Bug: Indentation Error in method docstring #497

Closed
@jauerb

Description

@jauerb

I have been experiencing a weird bug, and this is the most minimal example I have been able to come up with

test.py:

"""Minimal example of pydocstyle bug."""

class Bug:
    """Seems to only happen with method inside of a class."""

    def do_something(x):
        """Do something.

        Args:
            x: some value
        """
        print(f"""{x}
""")

If I run
pydocstyle test.py

I get

$ pydocstyle test.py 
Traceback (most recent call last):
  File "ENVIRONMENT_PATH/bin/pydocstyle", line 8, in <module>
    sys.exit(main())
  File "ENVIRONMENT_PATH/lib/python3.7/site-packages/pydocstyle/cli.py", line 68, in main
    sys.exit(run_pydocstyle())
  File "ENVIRONMENT_PATH/lib/python3.7/site-packages/pydocstyle/cli.py", line 45, in run_pydocstyle
    ignore_decorators=ignore_decorators))
  File "ENVIRONMENT_PATH/lib/python3.7/site-packages/pydocstyle/checker.py", line 969, in check
    ignore_decorators):
  File "ENVIRONMENT_PATH/lib/python3.7/site-packages/pydocstyle/checker.py", line 123, in check_source
    for error in errors:
  File "ENVIRONMENT_PATH/lib/python3.7/site-packages/pydocstyle/checker.py", line 917, in check_docstring_sections
    yield from self._check_google_sections(lines, definition, docstring)
  File "ENVIRONMENT_PATH/lib/python3.7/site-packages/pydocstyle/checker.py", line 903, in _check_google_sections
    yield from self._check_google_section(docstring, definition, ctx)
  File "ENVIRONMENT_PATH/lib/python3.7/site-packages/pydocstyle/checker.py", line 796, in _check_google_section
    yield from cls._check_args_section(docstring, definition, context)
  File "ENVIRONMENT_PATH/lib/python3.7/site-packages/pydocstyle/checker.py", line 748, in _check_args_section
    yield from ConventionChecker._check_missing_args(docstring_args, definition)
  File "ENVIRONMENT_PATH/lib/python3.7/site-packages/pydocstyle/checker.py", line 762, in _check_missing_args
    function_args = get_function_args(definition.source)
  File "ENVIRONMENT_PATH/lib/python3.7/site-packages/pydocstyle/checker.py", line 1002, in get_function_args
    function_arg_node = ast.parse(textwrap.dedent(function_string)).body[0].args
  File "ENVIRONMENT_PATH/lib/python3.7/ast.py", line 35, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
  File "<unknown>", line 1
    def do_something(x):
    ^
IndentationError: unexpected indent

But the file parses fine by the Python interpreter, and it goes away if I either omit the multiline string literal, omit the Args: block of my docstring, or add a Returns: or Raises: block after the Args: block (adding other stuff there does not seem to fix the issue).

My environment details
Python 3.7.7 on Linux (though have also seen on other versions)

$ pip freeze
certifi==2020.6.20
pydocstyle==5.0.2
snowballstemmer==2.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions