Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: Remove sequential blank lines in docstrings #9451

Open
stinodego opened this issue Jan 10, 2024 · 6 comments
Open

Request: Remove sequential blank lines in docstrings #9451

stinodego opened this issue Jan 10, 2024 · 6 comments
Labels
docstring Related to docstring linting or formatting rule Implementing or modifying a lint rule

Comments

@stinodego
Copy link
Contributor

stinodego commented Jan 10, 2024

I'd like a way to get rid of extraneous whitespace in docstrings.

Here's an example of a docstring with way too much whitespace:

def cool_function(x: int) -> None:
    """
    Do nothing.

    Parameters
    ----------
    x
        Description of x.



    Notes
    -----
    Hello.


    There.


    """

I'd like ruff to format this down to:

def cool_function(x: int) -> None:
    """
    Do nothing.

    Parameters
    ----------
    x
        Description of x.

    Notes
    -----
    Hello.

    There.

    """

On a related note, there is currently no way to make sure there is no blank line after the last section (the opposite of D413). This would be a useful lint to have!

@charliermarsh charliermarsh added the docstring Related to docstring linting or formatting label Jan 10, 2024
@charliermarsh
Copy link
Member

This looks useful.

@charliermarsh charliermarsh added the rule Implementing or modifying a lint rule label Jan 10, 2024
@MichaReiser
Copy link
Member

@stinodego would you expect this to happen as part of a lint rule or are you asking for docstring formatting?

@stinodego
Copy link
Contributor Author

I honestly don't really know what the difference is between the two. Either is fine with me!

@BrentWilkins
Copy link

BrentWilkins commented Feb 6, 2024

This looks related to a change in this PR. Ruff is calling this docstring bad:

"""Make a summary line.

Note:
----
  Per the code comment the next two lines are blank. "// The first blank line is the line containing the closing
      triple quotes, so we need at least two."

"""

Missing blank line after last section ("Note") Ruff(D413)

I can't see what's different between what I have and the Use instead: section of the documentation.

I can make Ruff happy by adding excessive blank lines:

"""Make a summary line.

Note:
----
  Per the code comment the next two lines are blank. "// The first blank line is the line containing the closing
      triple quotes, so we need at least two."


"""

@charliermarsh
Copy link
Member

Seems like a bug in D413 (which was incorrectly implemented before that PR, and never really triggered), but I don't think it's related to this issue per se?

@BrentWilkins
Copy link

Only in as much as this issue is to remove excessive whitespace like that bug is enforcing. I'll create a new issue for that. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docstring Related to docstring linting or formatting rule Implementing or modifying a lint rule
Projects
None yet
Development

No branches or pull requests

4 participants