Add missing docstring sections to the numpy list (#20931)

<!--
Thank you for contributing to Ruff/ty! To help us out with reviewing,
please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title? (Please prefix
with `[ty]` for ty pull
  requests.)
- Does this pull request include references to any relevant issues?
-->

## Summary

Add docstring sections which were missing from the numpy list as pointed
out here #20923. For now these are only the official sections as
documented
[here](https://numpydoc.readthedocs.io/en/latest/format.html#sections).

## Test Plan

Added a test case for DOC102
This commit is contained in:
Auguste Lalande 2025-10-24 17:19:30 -04:00 committed by GitHub
parent 1ade9a5943
commit 64ab79e572
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 2 deletions

View File

@ -370,3 +370,22 @@ class Foo:
The flag converter instance with all flags parsed. The flag converter instance with all flags parsed.
""" """
return return
# OK
def baz(x: int) -> int:
"""
Show a `Warnings` DOC102 false positive.
Parameters
----------
x : int
Warnings
--------
This function demonstrates a DOC102 false positive
Returns
-------
int
"""
return x

View File

@ -11,6 +11,8 @@ pub(crate) static GOOGLE_SECTIONS: &[SectionKind] = &[
SectionKind::References, SectionKind::References,
SectionKind::Returns, SectionKind::Returns,
SectionKind::SeeAlso, SectionKind::SeeAlso,
SectionKind::Warnings,
SectionKind::Warns,
SectionKind::Yields, SectionKind::Yields,
// Google-only // Google-only
SectionKind::Args, SectionKind::Args,
@ -32,7 +34,5 @@ pub(crate) static GOOGLE_SECTIONS: &[SectionKind] = &[
SectionKind::Tip, SectionKind::Tip,
SectionKind::Todo, SectionKind::Todo,
SectionKind::Warning, SectionKind::Warning,
SectionKind::Warnings,
SectionKind::Warns,
SectionKind::Yield, SectionKind::Yield,
]; ];

View File

@ -11,11 +11,14 @@ pub(crate) static NUMPY_SECTIONS: &[SectionKind] = &[
SectionKind::References, SectionKind::References,
SectionKind::Returns, SectionKind::Returns,
SectionKind::SeeAlso, SectionKind::SeeAlso,
SectionKind::Warnings,
SectionKind::Warns,
SectionKind::Yields, SectionKind::Yields,
// NumPy-only // NumPy-only
SectionKind::ExtendedSummary, SectionKind::ExtendedSummary,
SectionKind::OtherParams, SectionKind::OtherParams,
SectionKind::OtherParameters, SectionKind::OtherParameters,
SectionKind::Parameters, SectionKind::Parameters,
SectionKind::Receives,
SectionKind::ShortSummary, SectionKind::ShortSummary,
]; ];

View File

@ -36,6 +36,7 @@ pub(crate) enum SectionKind {
OtherParameters, OtherParameters,
Parameters, Parameters,
Raises, Raises,
Receives,
References, References,
Return, Return,
Returns, Returns,
@ -76,6 +77,7 @@ impl SectionKind {
"other parameters" => Some(Self::OtherParameters), "other parameters" => Some(Self::OtherParameters),
"parameters" => Some(Self::Parameters), "parameters" => Some(Self::Parameters),
"raises" => Some(Self::Raises), "raises" => Some(Self::Raises),
"receives" => Some(Self::Receives),
"references" => Some(Self::References), "references" => Some(Self::References),
"return" => Some(Self::Return), "return" => Some(Self::Return),
"returns" => Some(Self::Returns), "returns" => Some(Self::Returns),
@ -117,6 +119,7 @@ impl SectionKind {
Self::OtherParameters => "Other Parameters", Self::OtherParameters => "Other Parameters",
Self::Parameters => "Parameters", Self::Parameters => "Parameters",
Self::Raises => "Raises", Self::Raises => "Raises",
Self::Receives => "Receives",
Self::References => "References", Self::References => "References",
Self::Return => "Return", Self::Return => "Return",
Self::Returns => "Returns", Self::Returns => "Returns",