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

D205 false positive from Ruff on python script #15785

Open
vpkarle opened this issue Jan 28, 2025 · 3 comments
Open

D205 false positive from Ruff on python script #15785

vpkarle opened this issue Jan 28, 2025 · 3 comments
Labels
question Asking for support or clarification

Comments

@vpkarle
Copy link

vpkarle commented Jan 28, 2025

Description

Summary:
Ruff is flagging a D205 warning (blank line required) on docstrings even though the code is compliant with the rule.
The script complies with pydocstyle checks.

Steps to reproduce:
Create a python script file (myFile.py) which with below lines.

"""
This script processes images in a folder, extracts metadata,
and displays metadata.

See ReadMe for more details.
"""

import os
import subprocess
import sys

Run command "ruff check myFile.py"

Actual output:

myFile.py:1:1: D205 1 blank line required between summary line and description
  |
1 | / """
2 | | This script processes images in a folder, extracts metadata,
3 | | and displays metadata.
4 | |
5 | | See ReadMe for more details.
6 | | """
  | |___^ D205
7 |
8 |   import cv2
  |
  = help: Insert single blank line

Expected behavior:
Ruff should not flag this docstring with a D205 warning.

Version: ruff-0.9.3

@ntBre
Copy link
Contributor

ntBre commented Jan 28, 2025

I can reproduce this with this code and ruff check --select D205 d205.py. I'll have to check the intention behind D205 to know if this is a bug or intended behavior, but I also noticed that if you put the whole first/summary line on a single line, it doesn't trigger D205:

"""
This script processes images in a folder, extracts metadata, and displays metadata.

See ReadMe for more details.
"""

import os
import subprocess
import sys

@dhruvmanila
Copy link
Member

I think the rule only checks for first line without considering whether the line actually finishes the sentence or not. So, it's seeing that there's no blank line after "extracts metadata," which triggers the diagnostic. The PEP does specify "one-line summary" but I can't find if that allows the summary itself to be multiline, I think it doesn't. If so, then this is working as expected. What do you think @ntBre ?

@dhruvmanila dhruvmanila added the question Asking for support or clarification label Jan 29, 2025
@ntBre
Copy link
Contributor

ntBre commented Jan 29, 2025

I think you're right that it's working as intended. From PEP 257:

Multi-line docstrings consist of a summary line just like a one-line docstring, followed by a blank line, followed by a more elaborate description. The summary line may be used by automatic indexing tools; it is important that it fits on one line and is separated from the rest of the docstring by a blank line.

The numpy and Google style guides linked from the pydocstyle docs are similar, with Google's probably being the clearest:

A docstring should be organized as a summary line (one physical line not exceeding 80 characters)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking for support or clarification
Projects
None yet
Development

No branches or pull requests

3 participants