mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:21 +00:00
When "Args" and "Parameters" are present, prefer NumPy style (#3430)
This commit is contained in:
parent
2383228709
commit
872829ca72
1 changed files with 12 additions and 12 deletions
|
@ -294,18 +294,6 @@ pub fn sections(checker: &mut Checker, docstring: &Docstring, convention: Option
|
||||||
// (e.g., "Returns", "Raises"). Break ties by checking for the presence of some of the
|
// (e.g., "Returns", "Raises"). Break ties by checking for the presence of some of the
|
||||||
// section names that are unique to each convention.
|
// section names that are unique to each convention.
|
||||||
|
|
||||||
// If the docstring contains `Args:` or `Arguments:`, use the Google convention.
|
|
||||||
let google_sections = section_contexts(&lines, &SectionStyle::Google);
|
|
||||||
if google_sections
|
|
||||||
.iter()
|
|
||||||
.any(|context| matches!(context.kind, SectionKind::Arguments | SectionKind::Args))
|
|
||||||
{
|
|
||||||
for context in &google_sections {
|
|
||||||
google_section(checker, docstring, context);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the docstring contains `Parameters:` or `Other Parameters:`, use the NumPy
|
// If the docstring contains `Parameters:` or `Other Parameters:`, use the NumPy
|
||||||
// convention.
|
// convention.
|
||||||
let numpy_sections = section_contexts(&lines, &SectionStyle::Numpy);
|
let numpy_sections = section_contexts(&lines, &SectionStyle::Numpy);
|
||||||
|
@ -321,6 +309,18 @@ pub fn sections(checker: &mut Checker, docstring: &Docstring, convention: Option
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the docstring contains `Args:` or `Arguments:`, use the Google convention.
|
||||||
|
let google_sections = section_contexts(&lines, &SectionStyle::Google);
|
||||||
|
if google_sections
|
||||||
|
.iter()
|
||||||
|
.any(|context| matches!(context.kind, SectionKind::Arguments | SectionKind::Args))
|
||||||
|
{
|
||||||
|
for context in &google_sections {
|
||||||
|
google_section(checker, docstring, context);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Otherwise, use whichever convention matched more sections.
|
// Otherwise, use whichever convention matched more sections.
|
||||||
if google_sections.len() > numpy_sections.len() {
|
if google_sections.len() > numpy_sections.len() {
|
||||||
for context in &google_sections {
|
for context in &google_sections {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue