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

D202: Conflict with black's 2023 style #2592

Closed
ngnpope opened this issue Feb 5, 2023 · 1 comment · Fixed by #2597
Closed

D202: Conflict with black's 2023 style #2592

ngnpope opened this issue Feb 5, 2023 · 1 comment · Fixed by #2597
Labels
bug Something isn't working docstring Related to docstring linting or formatting

Comments

@ngnpope
Copy link
Contributor

ngnpope commented Feb 5, 2023

For the following code:

def outer():
    """This is a docstring."""
    # This is a comment.
    def inner():
        return

    return inner

I see the following behaviour:

ruff --version
ruff 0.0.240ruff --select D202 bug.py
# ... no output ...black --version
black, 23.1.0 (compiled: yes)
Python (CPython) 3.10.9black --diff bug.py 
--- bug.py	2023-02-05 21:19:16.413892 +0000
+++ bug.py	2023-02-05 21:19:22.497046 +0000
@@ -1,7 +1,8 @@
 def outer():
     """This is a docstring."""
+
     # This is a comment.
     def inner():
         return
 
     return inner()
would reformat bug.py

All done! ✨ 🍰 ✨
1 file would be reformatted.black bug.py 
reformatted bug.py

All done! ✨ 🍰 ✨
1 file reformatted.ruff --select D202 bug.py 
bug.py:2:5: D202 No blank lines allowed after function docstring (found 1)
Found 1 error.
1 potentially fixable with the --fix option.

It seems that this works fine if the comment is removed. Black wants a blank line before and after a nested function. But black treats comment lines before the function as "attached" to the function. This doesn't happen with the D202 rule in ruff which treats them as separate. We should follow black's lead here.

@ngnpope
Copy link
Contributor Author

ngnpope commented Feb 5, 2023

Related: PyCQA/pydocstyle#627

@charliermarsh charliermarsh added bug Something isn't working docstring Related to docstring linting or formatting labels Feb 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working docstring Related to docstring linting or formatting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants