-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
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 :
ruff/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs
Lines 2176 to 2193 in f8b0b0f
| 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