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

Minimize the docstring line numbers offset introduced by napoleon #807

Open
tristanlatr opened this issue Jul 8, 2024 · 0 comments
Open

Comments

@tristanlatr
Copy link
Contributor

The napoleon docstring preprocessor has been ported from sphinx. It's a great and complete piece of code. It has only one drawback, and that's the fact that it messes up with the line numbers of docstring fields. It is a completely normal side effect since the code operates as a string transformer before parsing it with docutils.

Even for the simplest example, some offset will be of 1, and this is probably best to accept otherwise we have to look at re-implementing the whole google and numpy parsing. And this is not a viable option for the moment. So let's say an offset of 1 is acceptable. But still I wonder if we could ensure at any time len(original_docsstring.splitlines()) == len(transformed_docstring.splitlines()).

Anyway here goes a few examples of cases that could be improved:

Example Function

Raises:
    InvalidDimensionsError: With description

Is transformed into :

Example Function

:raises InvalidDimensionsError: With description

But it would best if that was

Example Function


:raises InvalidDimensionsError: With description

And

Example Function

Raises:
    InvalidDimensionsError: 
        With description

Is transformed into the same :

Example Function

:raises InvalidDimensionsError: With description

But it would best if that was

Example Function


:raises InvalidDimensionsError: 
    With description

So now look at example where the line number diffs are greater

Example Function

Raises:
    RuntimeError:
        A setting wasn't specified, or was invalid.
    ValueError:
        Something something value error.
    :py:class:`AttributeError`
        errors for missing attributes.
    ~InvalidDimensionsError
        If the dimensions couldn't be parsed.
    `InvalidArgumentsError`
        If the arguments are invalid.
    :exc:`~ValueError`
        If the arguments are wrong.

Is transformed into :

Example Function

:raises RuntimeError: A setting wasn't specified, or was invalid.
:raises ValueError: Something something value error.
:raises AttributeError: errors for missing attributes.
:raises ~InvalidDimensionsError: If the dimensions couldn't be parsed.
:raises InvalidArgumentsError: If the arguments are invalid.
:raises ~ValueError: If the arguments are wrong.

But it would best if that was

Example Function


:raises RuntimeError: 
    A setting wasn't specified, or was invalid.
:raises ValueError: 
    Something something value error.
:raises AttributeError: 
    errors for missing attributes.
:raises ~InvalidDimensionsError: 
    If the dimensions couldn't be parsed.
:raises InvalidArgumentsError: 
    If the arguments are invalid.
:raises ~ValueError: 
    If the arguments are wrong.

Another interesting example is the return clause that is translated to two fields.

Example Function

Returns:
    :class:`numpy.ndarray`: A :math:`n \\times 2` array containing
    a bunch of math items

Is transformed into :

Example Function

:returns: A :math:`n \\times 2` array containing
          a bunch of math items
:returntype: :class:`numpy.ndarray`

But it would best if that was

Example Function

:returntype: :class:`numpy.ndarray`
:returns: A :math:`n \\times 2` array containing
          a bunch of math items
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant