Skip to content

Commit d6bd841

Browse files
[pydoclint] Ignore DOC201 when function name is "__new__" (#13300)
1 parent 210a9e6 commit d6bd841

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

crates/ruff_linter/resources/test/fixtures/pydoclint/DOC201_google.py

+7
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,10 @@ def foo(s: str) -> str | None:
207207
s (str): A string.
208208
"""
209209
return None
210+
211+
212+
class Spam:
213+
# OK
214+
def __new__(cls) -> 'Spam':
215+
"""New!!"""
216+
return cls()

crates/ruff_linter/src/rules/pydoclint/rules/check_docstring.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,10 @@ fn returns_documented(
741741
|| (matches!(convention, Some(Convention::Google)) && starts_with_returns(docstring))
742742
}
743743

744+
fn should_document_returns(function_def: &ast::StmtFunctionDef) -> bool {
745+
!matches!(function_def.name.as_str(), "__new__")
746+
}
747+
744748
fn starts_with_yields(docstring: &Docstring) -> bool {
745749
if let Some(first_word) = docstring.body().as_str().split(' ').next() {
746750
return matches!(first_word, "Yield" | "Yields");
@@ -868,7 +872,9 @@ pub(crate) fn check_docstring(
868872

869873
// DOC201
870874
if checker.enabled(Rule::DocstringMissingReturns) {
871-
if !returns_documented(docstring, &docstring_sections, convention) {
875+
if should_document_returns(function_def)
876+
&& !returns_documented(docstring, &docstring_sections, convention)
877+
{
872878
let extra_property_decorators = checker.settings.pydocstyle.property_decorators();
873879
if !definition.is_property(extra_property_decorators, semantic) {
874880
if let Some(body_return) = body_entries.returns.first() {

0 commit comments

Comments
 (0)