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

Google style hanging indent on line break #625

Open
sebastian-correa opened this issue Jan 9, 2023 · 0 comments
Open

Google style hanging indent on line break #625

sebastian-correa opened this issue Jan 9, 2023 · 0 comments

Comments

@sebastian-correa
Copy link

Issue

According to Google's Style Guide, if a line in the Args section needs to be broken due to length, you should use a hanging indent for the next lines [ref].

If the description is too long to fit on a single 80-character line, use a hanging indent of 2 or 4 spaces more than the parameter name (be consistent with the rest of the docstrings in the file).

I guess this is also the case for other valid sections in the docstring.

Example

This must be a case of misconfiguration, but running pydocstyle --convetion=google doesn't suggest those fixes in my case. For example, I would expect the following docstring

def add(a: int, b: int) -> int:
    """Add a and b.

    Args:
        a (int): Number 1 to be added. This line is intentionally long to cause
         a mandatory break.
        b (int): Number 2 to be added. This line is intentionally long to cause
        a mandatory break.
    """
    return a + b

to be flagged as incorrect because the correct Google-style docstring would be

def add(a: int, b: int) -> int:
    """Add a and b.

    Args:
        a (int): Number 1 to be added. This line is intentionally long to cause
            a mandatory break.
        b (int): Number 2 to be added. This line is intentionally long to cause
            a mandatory break.
    """
    return a + b

Instead, pydocstyle doesn't complain.

The correct hanging indent can be detected by measuring the hanging indent between Args: and the first arg, for example.

Am I doing something wrong?

Environment

  • Mac OS 12.5.1 on an Intel Mac.
  • Python 3.10.8.
  • pydocstyle 6.2.2.
@sebastian-correa sebastian-correa changed the title Google style handing indent on line break Google style hanging indent on line break Jan 10, 2023
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

1 participant