Skip to content

Commit

Permalink
fix: IndexError when only URL in long description (#190)
Browse files Browse the repository at this point in the history
* fix: IndexError with only URL in long description

* test: for IndexError with only URL in long description
  • Loading branch information
weibullguy committed Apr 26, 2023
1 parent 1cb6545 commit 93ed4d7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/docformatter/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,9 @@ def do_split_description(
)
)

if _lines[-1] == "":
_lines.pop(-1)
with contextlib.suppress(IndexError):
if _lines[-1] == "":
_lines.pop(-1)

# Add the URL.
_lines.append(
Expand Down
37 changes: 37 additions & 0 deletions tests/test_format_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,43 @@ def test_format_docstring_with_short_link(
INDENTATION, docstring.strip()
)

@pytest.mark.unit
@pytest.mark.parametrize(
"args",
[["--wrap-descriptions", "72", ""]],
)
def test_format_docstring_with_only_link_in_description(
self,
test_args,
args,
):
"""No index error when only link in long description.
See issue #189.
"""
uut = Formatter(
test_args,
sys.stderr,
sys.stdin,
sys.stdout,
)

docstring = '''\
"""This method doesn't do anything.
https://example.com/this-is-just-a-long-url/designed-to-trigger/the-wrapping-of-the-description
"""
'''

assert '''\
"""This method doesn\'t do anything.
https://example.com/this-is-just-a-long-url/designed-to-trigger/the-wrapping-of-the-description
"""\
''' == uut._do_format_docstring(
INDENTATION, docstring.strip()
)

@pytest.mark.unit
@pytest.mark.parametrize(
"args",
Expand Down

0 comments on commit 93ed4d7

Please sign in to comment.