Skip to content

Commit 69d0caa

Browse files
authored
fix D417 error with function docstrings with dashed lines (#7251)
## Summary Fix #7250, False positive D417 for docstrings with dashed lines. ## Test Plan Tested on the example in #7250
1 parent 9cb5ce7 commit 69d0caa

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

crates/ruff/resources/test/fixtures/pydocstyle/D417.py

+13
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,19 @@ def f(x, *, y, z):
128128
"""
129129
return x, y, z
130130

131+
def f(x):
132+
"""Do something with valid description.
133+
134+
Args:
135+
----
136+
x: the value
137+
138+
Returns:
139+
-------
140+
the value
141+
"""
142+
return x
143+
131144

132145
class Test:
133146
def f(self, /, arg1: int) -> None:

crates/ruff/src/rules/pydocstyle/rules/sections.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1377,9 +1377,7 @@ fn blanks_and_section_underline(
13771377
}
13781378

13791379
if let Some(non_blank_line) = following_lines.next() {
1380-
let dash_line_found = non_blank_line
1381-
.chars()
1382-
.all(|char| char.is_whitespace() || char == '-');
1380+
let dash_line_found = is_dashed_underline(&non_blank_line);
13831381

13841382
if dash_line_found {
13851383
if blank_lines_after_header > 0 {
@@ -1798,7 +1796,9 @@ fn args_section(context: &SectionContext) -> FxHashSet<String> {
17981796
let relevant_lines = std::iter::once(first_line)
17991797
.chain(following_lines)
18001798
.map(|l| l.as_str())
1801-
.filter(|line| line.starts_with(leading_space) || line.is_empty())
1799+
.filter(|line| {
1800+
line.is_empty() || (line.starts_with(leading_space) && !is_dashed_underline(line))
1801+
})
18021802
.join("\n");
18031803
let args_content = dedent(&relevant_lines);
18041804

@@ -1989,3 +1989,8 @@ fn parse_google_sections(
19891989
}
19901990
}
19911991
}
1992+
1993+
fn is_dashed_underline(line: &str) -> bool {
1994+
let trimmed_line = line.trim();
1995+
!trimmed_line.is_empty() && trimmed_line.chars().all(|char| char == '-')
1996+
}

0 commit comments

Comments
 (0)