Skip to content

Commit 93ed4d7

Browse files
authored
fix: IndexError when only URL in long description (#190)
* fix: IndexError with only URL in long description * test: for IndexError with only URL in long description
1 parent 1cb6545 commit 93ed4d7

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/docformatter/syntax.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,9 @@ def do_split_description(
338338
)
339339
)
340340

341-
if _lines[-1] == "":
342-
_lines.pop(-1)
341+
with contextlib.suppress(IndexError):
342+
if _lines[-1] == "":
343+
_lines.pop(-1)
343344

344345
# Add the URL.
345346
_lines.append(

tests/test_format_docstring.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,43 @@ def test_format_docstring_with_short_link(
12981298
INDENTATION, docstring.strip()
12991299
)
13001300

1301+
@pytest.mark.unit
1302+
@pytest.mark.parametrize(
1303+
"args",
1304+
[["--wrap-descriptions", "72", ""]],
1305+
)
1306+
def test_format_docstring_with_only_link_in_description(
1307+
self,
1308+
test_args,
1309+
args,
1310+
):
1311+
"""No index error when only link in long description.
1312+
1313+
See issue #189.
1314+
"""
1315+
uut = Formatter(
1316+
test_args,
1317+
sys.stderr,
1318+
sys.stdin,
1319+
sys.stdout,
1320+
)
1321+
1322+
docstring = '''\
1323+
"""This method doesn't do anything.
1324+
1325+
https://example.com/this-is-just-a-long-url/designed-to-trigger/the-wrapping-of-the-description
1326+
"""
1327+
'''
1328+
1329+
assert '''\
1330+
"""This method doesn\'t do anything.
1331+
1332+
https://example.com/this-is-just-a-long-url/designed-to-trigger/the-wrapping-of-the-description
1333+
"""\
1334+
''' == uut._do_format_docstring(
1335+
INDENTATION, docstring.strip()
1336+
)
1337+
13011338
@pytest.mark.unit
13021339
@pytest.mark.parametrize(
13031340
"args",

0 commit comments

Comments
 (0)