-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore DOC
errors for stub functions
#12651
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,8 @@ use ruff_python_ast::helpers::map_callable; | |
use ruff_python_ast::name::QualifiedName; | ||
use ruff_python_ast::visitor::Visitor; | ||
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 crate::checkers::ast::Checker; | ||
|
@@ -645,15 +646,14 @@ pub(crate) fn check_docstring( | |
convention: Option<Convention>, | ||
) { | ||
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; | ||
}; | ||
|
||
// Only check function docstrings. | ||
if matches!( | ||
member.kind, | ||
MemberKind::Class(_) | MemberKind::NestedClass(_) | ||
) { | ||
// Ignore stubs. | ||
if function_type::is_stub(function_def, checker.semantic()) { | ||
return; | ||
} | ||
|
||
|
@@ -670,17 +670,19 @@ pub(crate) fn check_docstring( | |
|
||
let body_entries = { | ||
let mut visitor = BodyVisitor::new(checker.semantic()); | ||
visitor.visit_body(member.body()); | ||
visitor.visit_body(&function_def.body); | ||
visitor.finish() | ||
}; | ||
|
||
// DOC201 | ||
if checker.enabled(Rule::DocstringMissingReturns) && docstring_sections.returns.is_none() { | ||
let extra_property_decorators = checker.settings.pydocstyle.property_decorators(); | ||
if !definition.is_property(extra_property_decorators, checker.semantic()) { | ||
if let Some(body_return) = body_entries.returns.first() { | ||
let diagnostic = Diagnostic::new(DocstringMissingReturns, body_return.range()); | ||
diagnostics.push(diagnostic); | ||
if checker.enabled(Rule::DocstringMissingReturns) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this change just a stylistic preference? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I prefer to have the enablement checks separated out from any lint-specific checks. I find it to be a clearer separation, and it would make it easier to identify and automatically rewrite them in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense, thanks |
||
if docstring_sections.returns.is_none() { | ||
let extra_property_decorators = checker.settings.pydocstyle.property_decorators(); | ||
if !definition.is_property(extra_property_decorators, checker.semantic()) { | ||
if let Some(body_return) = body_entries.returns.first() { | ||
let diagnostic = Diagnostic::new(DocstringMissingReturns, body_return.range()); | ||
diagnostics.push(diagnostic); | ||
} | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this check now covered by is_stub?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's covered by the
immediately above