Skip to content

Commit

Permalink
[pydoclint] Ignore DOC201 when function name is "__new__" (#13300)
Browse files Browse the repository at this point in the history
  • Loading branch information
augustelalande authored Sep 10, 2024
1 parent 210a9e6 commit d6bd841
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit d6bd841

Please sign in to comment.