diff --git a/src/docformatter/syntax.py b/src/docformatter/syntax.py index 9afbeb6..567a995 100644 --- a/src/docformatter/syntax.py +++ b/src/docformatter/syntax.py @@ -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( diff --git a/tests/test_format_docstring.py b/tests/test_format_docstring.py index df1d764..92bc507 100644 --- a/tests/test_format_docstring.py +++ b/tests/test_format_docstring.py @@ -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",