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

List index out of range when formatting docstring with URL #189

Closed
natehardison opened this issue Apr 25, 2023 · 0 comments · Fixed by #190
Closed

List index out of range when formatting docstring with URL #189

natehardison opened this issue Apr 25, 2023 · 0 comments · Fixed by #190
Labels
C: style Relates to docstring format style (e.g., Google, NumPy, Sphinx) P: bug PEP 257 violation or existing functionality that doesn't work as documented
Milestone

Comments

@natehardison
Copy link

I'm on newly-released docformatter 1.6.3. When I run on a docstring of the following format, I get an IndexError: list index out of range at File ".../lib/python3.11/site-packages/docformatter/syntax.py", line 341, in do_split_description if _lines[-1] == "":

def method():
    """This method doesn't do anything.

    https://example.com/this-is-just-a-long-url/designed-to-trigger/the-wrapping-of-the-description
    """
$ docformatter test.py
Traceback (most recent call last):
  File "/Users/nate/testenv/bin/docformatter", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/nate/testenv/lib/python3.11/site-packages/docformatter/__main__.py", line 71, in main
    return _main(
           ^^^^^^
  File "/Users/nate/testenv/lib/python3.11/site-packages/docformatter/__main__.py", line 61, in _main
    return formator.do_format_files()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nate/testenv/lib/python3.11/site-packages/docformatter/format.py", line 158, in do_format_files
    result = self._do_format_file(filename)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nate/testenv/lib/python3.11/site-packages/docformatter/format.py", line 191, in _do_format_file
    formatted_source = self._do_format_code(source)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nate/testenv/lib/python3.11/site-packages/docformatter/format.py", line 236, in _do_format_code
    _code = self._format_code(source)
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nate/testenv/lib/python3.11/site-packages/docformatter/format.py", line 301, in _format_code
    token_string = self._do_format_docstring(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nate/testenv/lib/python3.11/site-packages/docformatter/format.py", line 393, in _do_format_docstring
    return self._do_format_multiline_docstring(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nate/testenv/lib/python3.11/site-packages/docformatter/format.py", line 496, in _do_format_multiline_docstring
    description = _syntax.wrap_description(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nate/testenv/lib/python3.11/site-packages/docformatter/syntax.py", line 519, in wrap_description
    lines = do_split_description(text, indentation, wrap_length)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nate/testenv/lib/python3.11/site-packages/docformatter/syntax.py", line 341, in do_split_description
    if _lines[-1] == "":
       ~~~~~~^^^^
IndexError: list index out of range

If I add any text between the summary line and the URL, then this goes away:

def method():
    """This docstring does not trigger an error.

    a
    https://example.com/this-is-just-a-long-url/designed-to-trigger/the-wrapping-of-the-description
    """
@github-actions github-actions bot added the fresh This is a new issue label Apr 25, 2023
@weibullguy weibullguy added P: bug PEP 257 violation or existing functionality that doesn't work as documented C: style Relates to docstring format style (e.g., Google, NumPy, Sphinx) and removed fresh This is a new issue labels Apr 25, 2023
@weibullguy weibullguy added this to the v1.7.0 milestone Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: style Relates to docstring format style (e.g., Google, NumPy, Sphinx) P: bug PEP 257 violation or existing functionality that doesn't work as documented
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants