fix D417 error with function docstrings with dashed lines (#7251)

## Summary

Fix https://github.com/astral-sh/ruff/issues/7250, False positive D417
for docstrings with dashed lines.

## Test Plan

Tested on the example in https://github.com/astral-sh/ruff/issues/7250
This commit is contained in:
Ely Ronnen 2023-09-10 19:28:44 +03:00 committed by GitHub
parent 9cb5ce750e
commit 69d0caabe7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 4 deletions

View file

@ -128,6 +128,19 @@ def f(x, *, y, z):
""" """
return x, y, z return x, y, z
def f(x):
"""Do something with valid description.
Args:
----
x: the value
Returns:
-------
the value
"""
return x
class Test: class Test:
def f(self, /, arg1: int) -> None: def f(self, /, arg1: int) -> None:

View file

@ -1377,9 +1377,7 @@ fn blanks_and_section_underline(
} }
if let Some(non_blank_line) = following_lines.next() { if let Some(non_blank_line) = following_lines.next() {
let dash_line_found = non_blank_line let dash_line_found = is_dashed_underline(&non_blank_line);
.chars()
.all(|char| char.is_whitespace() || char == '-');
if dash_line_found { if dash_line_found {
if blank_lines_after_header > 0 { if blank_lines_after_header > 0 {
@ -1798,7 +1796,9 @@ fn args_section(context: &SectionContext) -> FxHashSet<String> {
let relevant_lines = std::iter::once(first_line) let relevant_lines = std::iter::once(first_line)
.chain(following_lines) .chain(following_lines)
.map(|l| l.as_str()) .map(|l| l.as_str())
.filter(|line| line.starts_with(leading_space) || line.is_empty()) .filter(|line| {
line.is_empty() || (line.starts_with(leading_space) && !is_dashed_underline(line))
})
.join("\n"); .join("\n");
let args_content = dedent(&relevant_lines); let args_content = dedent(&relevant_lines);
@ -1989,3 +1989,8 @@ fn parse_google_sections(
} }
} }
} }
fn is_dashed_underline(line: &str) -> bool {
let trimmed_line = line.trim();
!trimmed_line.is_empty() && trimmed_line.chars().all(|char| char == '-')
}