mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 22:54:42 +00:00
Ignore DOC
errors for stub functions (#12651)
## Summary Closes https://github.com/astral-sh/ruff/issues/12650.
This commit is contained in:
parent
341a25eec1
commit
733341ab39
2 changed files with 27 additions and 14 deletions
|
@ -48,3 +48,14 @@ class Bar:
|
||||||
num (int): A number
|
num (int): A number
|
||||||
"""
|
"""
|
||||||
print('test')
|
print('test')
|
||||||
|
|
||||||
|
|
||||||
|
# See: https://github.com/astral-sh/ruff/issues/12650
|
||||||
|
class C:
|
||||||
|
def foo(self) -> int:
|
||||||
|
"""Calculate x.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
x
|
||||||
|
"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
|
@ -6,7 +6,8 @@ use ruff_python_ast::helpers::map_callable;
|
||||||
use ruff_python_ast::name::QualifiedName;
|
use ruff_python_ast::name::QualifiedName;
|
||||||
use ruff_python_ast::visitor::Visitor;
|
use ruff_python_ast::visitor::Visitor;
|
||||||
use ruff_python_ast::{self as ast, visitor, Expr, Stmt};
|
use ruff_python_ast::{self as ast, visitor, Expr, Stmt};
|
||||||
use ruff_python_semantic::{Definition, MemberKind, SemanticModel};
|
use ruff_python_semantic::analyze::function_type;
|
||||||
|
use ruff_python_semantic::{Definition, SemanticModel};
|
||||||
use ruff_text_size::{Ranged, TextRange};
|
use ruff_text_size::{Ranged, TextRange};
|
||||||
|
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
|
@ -656,15 +657,14 @@ pub(crate) fn check_docstring(
|
||||||
convention: Option<Convention>,
|
convention: Option<Convention>,
|
||||||
) {
|
) {
|
||||||
let mut diagnostics = Vec::new();
|
let mut diagnostics = Vec::new();
|
||||||
let Definition::Member(member) = definition else {
|
|
||||||
|
// Only check function docstrings.
|
||||||
|
let Some(function_def) = definition.as_function_def() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Only check function docstrings.
|
// Ignore stubs.
|
||||||
if matches!(
|
if function_type::is_stub(function_def, checker.semantic()) {
|
||||||
member.kind,
|
|
||||||
MemberKind::Class(_) | MemberKind::NestedClass(_)
|
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -681,17 +681,19 @@ pub(crate) fn check_docstring(
|
||||||
|
|
||||||
let body_entries = {
|
let body_entries = {
|
||||||
let mut visitor = BodyVisitor::new(checker.semantic());
|
let mut visitor = BodyVisitor::new(checker.semantic());
|
||||||
visitor.visit_body(member.body());
|
visitor.visit_body(&function_def.body);
|
||||||
visitor.finish()
|
visitor.finish()
|
||||||
};
|
};
|
||||||
|
|
||||||
// DOC201
|
// DOC201
|
||||||
if checker.enabled(Rule::DocstringMissingReturns) && docstring_sections.returns.is_none() {
|
if checker.enabled(Rule::DocstringMissingReturns) {
|
||||||
let extra_property_decorators = checker.settings.pydocstyle.property_decorators();
|
if docstring_sections.returns.is_none() {
|
||||||
if !definition.is_property(extra_property_decorators, checker.semantic()) {
|
let extra_property_decorators = checker.settings.pydocstyle.property_decorators();
|
||||||
if let Some(body_return) = body_entries.returns.first() {
|
if !definition.is_property(extra_property_decorators, checker.semantic()) {
|
||||||
let diagnostic = Diagnostic::new(DocstringMissingReturns, body_return.range());
|
if let Some(body_return) = body_entries.returns.first() {
|
||||||
diagnostics.push(diagnostic);
|
let diagnostic = Diagnostic::new(DocstringMissingReturns, body_return.range());
|
||||||
|
diagnostics.push(diagnostic);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue