Skip to content

Commit 948c28a

Browse files
committed
fix: handle case where class contains only docstring
1 parent 112a80b commit 948c28a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/docformatter/format.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,22 @@ def _get_class_docstring_newlines(
260260
The number of newlines to insert after the docstring.
261261
"""
262262
j = index + 1
263+
indention_level = tokens[index].start[1]
263264

264265
# The docstring is followed by a comment.
265266
if tokens[j].string.startswith("#"):
266267
return 0
267268

269+
while j < len(tokens):
270+
if tokens[j].type in (tokenize.NL, tokenize.NEWLINE):
271+
j += 1
272+
continue
273+
274+
if tokens[j].start[1] < indention_level:
275+
return 2
276+
277+
break
278+
268279
return 1
269280

270281

0 commit comments

Comments
 (0)