Skip to content

Commit

Permalink
Add documentation to non-empty-stub-body (#7519)
Browse files Browse the repository at this point in the history
## Summary

Add documentation to `non-empty-stub-body` (`PYI010`) rule. Related to
#2646.

## Test Plan

`python scripts/check_docs_formatted.py`
  • Loading branch information
tjkuson authored Sep 19, 2023
1 parent 4ae463d commit 36a60bd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions crates/ruff/src/rules/flake8_pyi/rules/non_empty_stub_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@ use ruff_text_size::Ranged;
use crate::checkers::ast::Checker;
use crate::registry::Rule;

/// ## What it does
/// Checks for non-empty function stub bodies.
///
/// ## Why is this bad?
/// Stub files are meant to be used as a reference for the interface of a
/// module, and should not contain any implementation details. Thus, the
/// body of a stub function should be empty.
///
/// ## Example
/// ```python
/// def double(x: int) -> int:
/// return x * 2
/// ```
///
/// Use instead:
/// ```python
/// def double(x: int) -> int: ...
/// ```
///
/// ## References
/// - [PEP 484 – Type Hints: Stub Files](https://www.python.org/dev/peps/pep-0484/#stub-files)
#[violation]
pub struct NonEmptyStubBody;

Expand Down
1 change: 1 addition & 0 deletions scripts/check_docs_formatted.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"no-indented-block-comment",
"no-space-after-block-comment",
"no-space-after-inline-comment",
"non-empty-stub-body",
"one-blank-line-after-class",
"over-indentation",
"over-indented",
Expand Down

0 comments on commit 36a60bd

Please sign in to comment.