Skip to content

Commit 9268fd6

Browse files
jspaezpDanielNoord
andauthored
Fix crash on empty summary line with no whitespace option (#161)
Co-authored-by: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com>
1 parent 4dd7f6f commit 9268fd6

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ repos:
33
rev: v4.3.0
44
hooks:
55
- id: trailing-whitespace
6-
exclude: "tests/data/format/whitespace_stripper|tests/data/format/quotes_type|tests/data/format/newlines|tests/test_config.py"
6+
exclude: "tests/data/format/no_whitespace_stripper|tests/data/format/whitespace_stripper|tests/data/format/quotes_type|tests/data/format/newlines|tests/test_config.py"
77
- id: end-of-file-fixer
88
exclude: "tests/data/format/newlines"
99
- id: check-yaml

pydocstringformatter/_formatting/_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
def is_rst_title(summary: str) -> bool:
66
"""Check if the second line of a summary is one recurring character."""
77
# If second line is one recurring character we're dealing with a rst title
8-
last_line = summary.splitlines()[-1].lstrip()
8+
if not (last_line := summary.splitlines()[-1].lstrip()):
9+
return False
910
return last_line.count(last_line[0]) == len(last_line)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--no-strip-whitespaces
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
""" A multi-line
2+
docstring
3+
"""
4+
5+
""" A multi-line
6+
docstring
7+
"""
8+
9+
""" My docstring.
10+
11+
My indented section
12+
"""
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
""" A multi-line .
2+
3+
docstring
4+
"""
5+
6+
""" A multi-line .
7+
8+
docstring
9+
10+
"""
11+
12+
""" My docstring.
13+
14+
15+
16+
My indented section
17+
18+
"""

0 commit comments

Comments
 (0)