Skip to content

Implemented Numpy docstring sections order convention different from numpydoc #23682

@aulemahal

Description

@aulemahal

Summary

Hi! Last week, PR #23537 added checks for "D420", sections order in docstrings. It seems like the implemented expected order for numpy-style is different than what the source, numpydoc does.

I got an issue in a class docstring looking like this:

class Example:
    """
    An example class.

    Methods
    -------
    a_method

    Examples
    --------
    An example.

ruff says : D420 Section "Examples" appears after section "Methods" but should be before it
numpydoc say : GL07 Sections are in the wrong order. Correct order is: Methods, Examples

ruff implements the correct order here :

enum NumpySectionOrder {
ShortSummary,
ExtendedSummary,
Parameters,
Returns,
Yields,
Receives,
OtherParameters,
Raises,
Warns,
Warnings,
SeeAlso,
Notes,
References,
Examples,
Attributes,
Methods,
}

And numpydoc implements it here : https://github.com/numpy/numpydoc/blob/21dd5f5ef621d8b17b261654fbd0b188561493a4/numpydoc/validate.py#L28-L42

Most of the list is in the same order, but ruff's last two elements "Methods" and "Attributes" are much higher in the list from numpydoc. This simply looks like an oversight, because it doesn't make much sense to document those at the end. Also, those are probably rarely used, which might explain why the issue was not seen in the original PR.

Here, I am assuming that numpydoc is the "authoritative" source for the order, I might be wrong.

Version

ruff 0.15.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    docstringRelated to docstring linting or formattingpreviewRelated to preview mode featuresruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions