Skip to content

Commit 570825a

Browse files
authored
release: v1.6.1 (#175)
* chore: update version strings * fix: removing blank lines in function with no docstring * test: add test for function with no docstring * chore: update version strings
1 parent f1b0fa6 commit 570825a

File tree

5 files changed

+57
-13
lines changed

5 files changed

+57
-13
lines changed

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
project = 'docformatter'
1010
copyright = '2022-2023, Steven Myint'
1111
author = 'Steven Myint'
12-
release = '1.6.0'
12+
release = '1.6.1'
1313

1414
# -- General configuration ---------------------------------------------------
1515
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "docformatter"
3-
version = "1.6.0"
3+
version = "1.6.1"
44
description = "Formats docstrings to follow PEP 257"
55
authors = ["Steven Myint"]
66
maintainers = [

src/docformatter/__pkginfo__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
# SOFTWARE.
2424
"""Package information for docformatter."""
2525

26-
__version__ = "1.6.0"
26+
__version__ = "1.6.1"

src/docformatter/format.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -569,17 +569,31 @@ def _do_remove_blank_lines_after_docstring(modified_tokens):
569569
# statement as long as it's not a stub function.
570570
for _idx, _token in enumerate(modified_tokens):
571571
with contextlib.suppress(IndexError):
572+
_is_definition = (
573+
_token[4].lstrip().startswith(("class ", "def ", "@"))
574+
)
575+
_is_docstring = (
576+
modified_tokens[_idx - 2][4].strip().endswith('"""')
577+
)
578+
_after_definition = (
579+
modified_tokens[_idx - 6][4]
580+
.lstrip()
581+
.startswith(("class", "def", "@"))
582+
)
583+
_after_docstring = modified_tokens[_idx - 5][
584+
4
585+
].strip().endswith('"""') or modified_tokens[_idx - 5][
586+
4
587+
].strip().startswith(
588+
'"""'
589+
)
590+
572591
if (
573592
_token[0] == 1
574-
and not _token[4]
575-
.lstrip()
576-
.startswith(("class ", "def ", "@"))
577-
and not modified_tokens[_idx - 2][4]
578-
.strip()
579-
.endswith('"""')
580-
and modified_tokens[_idx - 6][4]
581-
.lstrip()
582-
.startswith(("class ", "def ", "@"))
593+
and not _is_definition
594+
and not _is_docstring
595+
and _after_definition
596+
and _after_docstring
583597
):
584598
j = 1
585599
while modified_tokens[_idx - j][4] == "\n":

tests/test_format_code.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ def test_format_code_strip_blank_line_after_class_variable(
10641064
):
10651065
"""Strip any newlines between a class variable defintion and docstring.
10661066
1067-
See issue #.
1067+
See requirement .
10681068
"""
10691069
uut = Formatter(
10701070
test_args,
@@ -1127,6 +1127,36 @@ def test_format_code_strip_blank_line_after_module_variable(
11271127
'''
11281128
)
11291129

1130+
@pytest.mark.unit
1131+
@pytest.mark.parametrize("args", [[""]])
1132+
def test_format_code_do_not_touch_function_no_docstring(
1133+
self,
1134+
test_args,
1135+
args,
1136+
):
1137+
"""Do not remove newlines in functions with no docstring.
1138+
1139+
See issue #156.
1140+
"""
1141+
uut = Formatter(
1142+
test_args,
1143+
sys.stderr,
1144+
sys.stdin,
1145+
sys.stdout,
1146+
)
1147+
1148+
docstring = '''\
1149+
def test_wps3_process_step_io_data_or_href():
1150+
"""Validates that \'data\' literal values and \'href\' file references are both
1151+
handled as input for workflow steps corresponding to a WPS-3 process."""
1152+
1153+
def mock_wps_request(method, url, *_, **kwargs):
1154+
nonlocal test_reached_parse_inputs
1155+
1156+
method = method.upper()
1157+
'''
1158+
assert docstring == uut._do_format_code(docstring)
1159+
11301160

11311161
class TestFormatCodeRanges:
11321162
"""Class for testing _format_code() with the line_range or length_range

0 commit comments

Comments
 (0)