Skip to content

Commit

Permalink
Refine recommendation around static methods (#8258)
Browse files Browse the repository at this point in the history
Closes #8025.
  • Loading branch information
charliermarsh authored Oct 26, 2023
1 parent 3e7b929 commit c36efe2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
10 changes: 4 additions & 6 deletions crates/ruff_linter/src/rules/pylint/rules/no_self_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{checkers::ast::Checker, rules::flake8_unused_arguments::helpers};
///
/// ## Why is this bad?
/// Unused `self` parameters are usually a sign of a method that could be
/// replaced by a function or a static method.
/// replaced by a function, class method, or static method.
///
/// ## Example
/// ```python
Expand All @@ -26,10 +26,8 @@ use crate::{checkers::ast::Checker, rules::flake8_unused_arguments::helpers};
///
/// Use instead:
/// ```python
/// class Person:
/// @staticmethod
/// def greeting():
/// print("Greetings friend!")
/// def greeting():
/// print("Greetings friend!")
/// ```
#[violation]
pub struct NoSelfUse {
Expand All @@ -40,7 +38,7 @@ impl Violation for NoSelfUse {
#[derive_message_formats]
fn message(&self) -> String {
let NoSelfUse { method_name } = self;
format!("Method `{method_name}` could be a function or static method")
format!("Method `{method_name}` could be a function, class method, or static method")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
source: crates/ruff_linter/src/rules/pylint/mod.rs
---
no_self_use.py:7:28: PLR6301 Method `developer_greeting` could be a function or static method
no_self_use.py:7:28: PLR6301 Method `developer_greeting` could be a function, class method, or static method
|
6 | class Person:
7 | def developer_greeting(self, name): # [no-self-use]
| ^^^^ PLR6301
8 | print(f"Greetings {name}!")
|

no_self_use.py:10:20: PLR6301 Method `greeting_1` could be a function or static method
no_self_use.py:10:20: PLR6301 Method `greeting_1` could be a function, class method, or static method
|
8 | print(f"Greetings {name}!")
9 |
Expand All @@ -18,7 +18,7 @@ no_self_use.py:10:20: PLR6301 Method `greeting_1` could be a function or static
11 | print("Hello!")
|

no_self_use.py:13:20: PLR6301 Method `greeting_2` could be a function or static method
no_self_use.py:13:20: PLR6301 Method `greeting_2` could be a function, class method, or static method
|
11 | print("Hello!")
12 |
Expand Down

0 comments on commit c36efe2

Please sign in to comment.