From 872829ca72edee272c0edcfd1c5ac3bcb805e53e Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 9 Mar 2023 21:58:05 -0500 Subject: [PATCH] When "Args" and "Parameters" are present, prefer NumPy style (#3430) --- .../src/rules/pydocstyle/rules/sections.rs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/ruff/src/rules/pydocstyle/rules/sections.rs b/crates/ruff/src/rules/pydocstyle/rules/sections.rs index d5ed6b0d6d..3680dc3026 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/sections.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/sections.rs @@ -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 // 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 // convention. let numpy_sections = section_contexts(&lines, &SectionStyle::Numpy); @@ -321,6 +309,18 @@ pub fn sections(checker: &mut Checker, docstring: &Docstring, convention: Option 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. if google_sections.len() > numpy_sections.len() { for context in &google_sections {