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

Bug: Indentation Error in method docstring #497

Closed
jauerb opened this issue Aug 7, 2020 · 4 comments
Closed

Bug: Indentation Error in method docstring #497

jauerb opened this issue Aug 7, 2020 · 4 comments

Comments

@jauerb
Copy link

jauerb commented Aug 7, 2020

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
@samj1912
Copy link
Member

samj1912 commented Aug 7, 2020

This is fixed on the master. We are preparing a new release soon

@samj1912
Copy link
Member

samj1912 commented Aug 7, 2020

Fixed by #441

Clone of the issue #437

@samj1912
Copy link
Member

samj1912 commented Aug 7, 2020

Can you retry with the master and see if you can replicate the error? Try pip install git+https://github.com/PyCQA/pydocstyle

Otherwise this might be a different error. Although I am fairly certain we have fixed this.

Closing for now, feel free to reopen if master doesn't work.

@samj1912 samj1912 closed this as completed Aug 7, 2020
@jauerb
Copy link
Author

jauerb commented Aug 7, 2020

Confirmed that it is fixed on master!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants