Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove blank after comment #177

Merged
merged 2 commits into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/docformatter/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import collections
import contextlib
import io
import re
import tokenize
from typing import TextIO, Tuple

Expand Down Expand Up @@ -587,11 +588,15 @@ def _do_remove_blank_lines_after_docstring(modified_tokens):
].strip().startswith(
'"""'
)
_comment_follows = re.search(
r"\"\"\" *#", modified_tokens[_idx - 4][4]
)

if (
_token[0] == 1
and not _is_definition
and not _is_docstring
and not _comment_follows
and _after_definition
and _after_docstring
):
Expand Down
43 changes: 43 additions & 0 deletions tests/test_format_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,49 @@ class AcceptLanguageHeader(ExtendedSchemaNode): \
# FIXME: oneOf validator for supported languages (?)'
assert docstring == uut._do_format_code(docstring)

@pytest.mark.unit
@pytest.mark.parametrize("args", [[""]])
def test_format_docstring_leave_blank_line_after_comment(self,
test_args,
args,):
"""Leave blank lines after docstring followed by a comment.

See issue #176.
"""
uut = Formatter(
test_args,
sys.stderr,
sys.stdin,
sys.stdout,
)

docstring = '''\
def Class1:
"""Class.""" #noqa

attribute
"""Attr."""


def Class2:
"""Class."""

attribute
"""Attr."""


def Class3:
"""Class docstring.

With long description.
""" #noqa

attribute
"""Attr."""
'''
assert docstring == uut._do_format_code(docstring)


class TestFormatLists:
"""Class for testing format_docstring() with lists in the docstring."""

Expand Down