Refine recommendation around static methods (#8258)

Closes https://github.com/astral-sh/ruff/issues/8025.
This commit is contained in:
Charlie Marsh 2023-10-26 12:03:53 -07:00 committed by GitHub
parent 3e7b92991b
commit c36efe254e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 9 deletions

View file

@ -15,7 +15,7 @@ use crate::{checkers::ast::Checker, rules::flake8_unused_arguments::helpers};
/// ///
/// ## Why is this bad? /// ## Why is this bad?
/// Unused `self` parameters are usually a sign of a method that could be /// 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 /// ## Example
/// ```python /// ```python
@ -26,8 +26,6 @@ use crate::{checkers::ast::Checker, rules::flake8_unused_arguments::helpers};
/// ///
/// Use instead: /// Use instead:
/// ```python /// ```python
/// class Person:
/// @staticmethod
/// def greeting(): /// def greeting():
/// print("Greetings friend!") /// print("Greetings friend!")
/// ``` /// ```
@ -40,7 +38,7 @@ impl Violation for NoSelfUse {
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
let NoSelfUse { method_name } = self; 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")
} }
} }

View file

@ -1,7 +1,7 @@
--- ---
source: crates/ruff_linter/src/rules/pylint/mod.rs 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: 6 | class Person:
7 | def developer_greeting(self, name): # [no-self-use] 7 | def developer_greeting(self, name): # [no-self-use]
@ -9,7 +9,7 @@ no_self_use.py:7:28: PLR6301 Method `developer_greeting` could be a function or
8 | print(f"Greetings {name}!") 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}!") 8 | print(f"Greetings {name}!")
9 | 9 |
@ -18,7 +18,7 @@ no_self_use.py:10:20: PLR6301 Method `greeting_1` could be a function or static
11 | print("Hello!") 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!") 11 | print("Hello!")
12 | 12 |