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

release: v1.6.1 #175

Merged
merged 4 commits into from
Apr 21, 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
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
project = 'docformatter'
copyright = '2022-2023, Steven Myint'
author = 'Steven Myint'
release = '1.6.0'
release = '1.6.1'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "docformatter"
version = "1.6.0"
version = "1.6.1"
description = "Formats docstrings to follow PEP 257"
authors = ["Steven Myint"]
maintainers = [
Expand Down
2 changes: 1 addition & 1 deletion src/docformatter/__pkginfo__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
# SOFTWARE.
"""Package information for docformatter."""

__version__ = "1.6.0"
__version__ = "1.6.1"
32 changes: 23 additions & 9 deletions src/docformatter/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,17 +569,31 @@ def _do_remove_blank_lines_after_docstring(modified_tokens):
# statement as long as it's not a stub function.
for _idx, _token in enumerate(modified_tokens):
with contextlib.suppress(IndexError):
_is_definition = (
_token[4].lstrip().startswith(("class ", "def ", "@"))
)
_is_docstring = (
modified_tokens[_idx - 2][4].strip().endswith('"""')
)
_after_definition = (
modified_tokens[_idx - 6][4]
.lstrip()
.startswith(("class", "def", "@"))
)
_after_docstring = modified_tokens[_idx - 5][
4
].strip().endswith('"""') or modified_tokens[_idx - 5][
4
].strip().startswith(
'"""'
)

if (
_token[0] == 1
and not _token[4]
.lstrip()
.startswith(("class ", "def ", "@"))
and not modified_tokens[_idx - 2][4]
.strip()
.endswith('"""')
and modified_tokens[_idx - 6][4]
.lstrip()
.startswith(("class ", "def ", "@"))
and not _is_definition
and not _is_docstring
and _after_definition
and _after_docstring
):
j = 1
while modified_tokens[_idx - j][4] == "\n":
Expand Down
32 changes: 31 additions & 1 deletion tests/test_format_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ def test_format_code_strip_blank_line_after_class_variable(
):
"""Strip any newlines between a class variable defintion and docstring.

See issue #.
See requirement .
"""
uut = Formatter(
test_args,
Expand Down Expand Up @@ -1127,6 +1127,36 @@ def test_format_code_strip_blank_line_after_module_variable(
'''
)

@pytest.mark.unit
@pytest.mark.parametrize("args", [[""]])
def test_format_code_do_not_touch_function_no_docstring(
self,
test_args,
args,
):
"""Do not remove newlines in functions with no docstring.

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

docstring = '''\
def test_wps3_process_step_io_data_or_href():
"""Validates that \'data\' literal values and \'href\' file references are both
handled as input for workflow steps corresponding to a WPS-3 process."""

def mock_wps_request(method, url, *_, **kwargs):
nonlocal test_reached_parse_inputs

method = method.upper()
'''
assert docstring == uut._do_format_code(docstring)


class TestFormatCodeRanges:
"""Class for testing _format_code() with the line_range or length_range
Expand Down