[`pydoclint`] Ignore `DOC201` when function name is "__new__" (#13300)

This commit is contained in:
Auguste Lalande 2024-09-10 13:25:38 -04:00 committed by GitHub
parent 210a9e6068
commit d6bd841512
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View File

@ -207,3 +207,10 @@ def foo(s: str) -> str | None:
s (str): A string.
"""
return None
class Spam:
# OK
def __new__(cls) -> 'Spam':
"""New!!"""
return cls()

View File

@ -741,6 +741,10 @@ fn returns_documented(
|| (matches!(convention, Some(Convention::Google)) && starts_with_returns(docstring))
}
fn should_document_returns(function_def: &ast::StmtFunctionDef) -> bool {
!matches!(function_def.name.as_str(), "__new__")
}
fn starts_with_yields(docstring: &Docstring) -> bool {
if let Some(first_word) = docstring.body().as_str().split(' ').next() {
return matches!(first_word, "Yield" | "Yields");
@ -868,7 +872,9 @@ pub(crate) fn check_docstring(
// DOC201
if checker.enabled(Rule::DocstringMissingReturns) {
if !returns_documented(docstring, &docstring_sections, convention) {
if should_document_returns(function_def)
&& !returns_documented(docstring, &docstring_sections, convention)
{
let extra_property_decorators = checker.settings.pydocstyle.property_decorators();
if !definition.is_property(extra_property_decorators, semantic) {
if let Some(body_return) = body_entries.returns.first() {