Ignore underlines when determining docstring logical lines (#8929)

This commit is contained in:
Charlie Marsh 2023-11-30 14:27:04 -05:00 committed by GitHub
parent 20782ab02c
commit d674e7946d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 2 deletions

View file

@ -10,8 +10,9 @@ pub(super) fn logical_line(content: &str) -> Option<usize> {
// Find the first logical line.
let mut logical_line = None;
for (i, line) in content.universal_newlines().enumerate() {
if line.trim().is_empty() {
// Empty line. If this is the line _after_ the first logical line, stop.
let trimmed = line.trim();
if trimmed.is_empty() || trimmed.chars().all(|c| matches!(c, '-' | '~' | '=' | '#')) {
// Empty line, or underline. If this is the line _after_ the first logical line, stop.
if logical_line.is_some() {
break;
}

View file

@ -247,4 +247,28 @@ D400.py:69:5: D400 [*] First line should end with a period
73 73 |
74 74 |
D400.py:97:5: D400 [*] First line should end with a period
|
96 | def f():
97 | """
| _____^
98 | | My example
99 | | ==========
100 | |
101 | | My example explanation
102 | | """
| |_______^ D400
|
= help: Add period
Unsafe fix
95 95 |
96 96 | def f():
97 97 | """
98 |- My example
98 |+ My example.
99 99 | ==========
100 100 |
101 101 | My example explanation