Skip to content

Missing docstring short description results in IndexError #520

@akaszynski

Description

@akaszynski

First off, thanks for the great library!

Error Description

A missing docstring short description results in IndexError, and exception makes the identification of the offending docstring quite difficult. This was discovered when using pre-commit with pydocstringformatter==0.7.5.

The following error is raised when the short description is missing:

pydocstringformatter.....................................................Failed
- hook id: pydocstringformatter
- exit code: 1

Traceback (most recent call last):
  File "/home/alex/.cache/pre-commit/repoa4sc2jje/py_env-python3.12/bin/pydocstringformatter", line 8, in <module>
    sys.exit(run_docstring_formatter())
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alex/.cache/pre-commit/repoa4sc2jje/py_env-python3.12/lib/python3.12/site-packages/pydocstringformatter/__init__.py", line 18, in run_docstring_formatter
    _Run(argv or sys.argv[1:])
  File "/home/alex/.cache/pre-commit/repoa4sc2jje/py_env-python3.12/lib/python3.12/site-packages/pydocstringformatter/run.py", line 34, in __init__
    self.check_files(self.config.files)
  File "/home/alex/.cache/pre-commit/repoa4sc2jje/py_env-python3.12/lib/python3.12/site-packages/pydocstringformatter/run.py", line 41, in check_files
    is_changed = self.format_files(filepaths)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alex/.cache/pre-commit/repoa4sc2jje/py_env-python3.12/lib/python3.12/site-packages/pydocstringformatter/run.py", line 202, in format_files
    is_changed = [self.format_file(file) for file in filepaths]
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alex/.cache/pre-commit/repoa4sc2jje/py_env-python3.12/lib/python3.12/site-packages/pydocstringformatter/run.py", line 68, in format_file
    formatted_tokens, is_changed = self.format_file_tokens(tokens, filename)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alex/.cache/pre-commit/repoa4sc2jje/py_env-python3.12/lib/python3.12/site-packages/pydocstringformatter/run.py", line 139, in format_file_tokens
    new_tokeninfo, changers = self.apply_formatters(new_tokeninfo)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alex/.cache/pre-commit/repoa4sc2jje/py_env-python3.12/lib/python3.12/site-packages/pydocstringformatter/run.py", line 177, in apply_formatters
    token, changers2 = self._apply_formatters_once(token)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alex/.cache/pre-commit/repoa4sc2jje/py_env-python3.12/lib/python3.12/site-packages/pydocstringformatter/run.py", line 194, in _apply_formatters_once
    if (new_token := formatter.treat_token(token)) != token:
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alex/.cache/pre-commit/repoa4sc2jje/py_env-python3.12/lib/python3.12/site-packages/pydocstringformatter/_formatting/base.py", line 100, in treat_token
    self.treat_string(
  File "/home/alex/.cache/pre-commit/repoa4sc2jje/py_env-python3.12/lib/python3.12/site-packages/pydocstringformatter/_formatting/base.py", line 281, in treat_string
    elif not section[0][0].isspace():
             ~~~~~~~~~~^^^
IndexError: string index out of range

Docstring

    def plot_mode_shape(
        self, show_surface: float = True, show_points: bool | None = None, **kwargs
    ):
        """
        Parameters
        ----------
        show_surface : bool, default: True
            Interpolate the mode shape onto the surface of the parent
            geometry if available.
        show_points : bool, optional
            By default, if ``show_surface=True``, points will not be shown.
        **kwargs : dict
            Optional keyword arguments. See :func:`pyvista.plot`. Camera view
            defaults to ``cpos="xy"``.

        Returns
        -------
        Any
            Any returns from :func:`pyvista.plot`.

        """

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions