From c36efe254e4fb349905d8ecd3c73f0bde73c18a6 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 26 Oct 2023 12:03:53 -0700 Subject: [PATCH] Refine recommendation around static methods (#8258) Closes https://github.com/astral-sh/ruff/issues/8025. --- .../ruff_linter/src/rules/pylint/rules/no_self_use.rs | 10 ++++------ ...__rules__pylint__tests__PLR6301_no_self_use.py.snap | 6 +++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/crates/ruff_linter/src/rules/pylint/rules/no_self_use.rs b/crates/ruff_linter/src/rules/pylint/rules/no_self_use.rs index 1be5e7d6372f0..eed411f123e63 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/no_self_use.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/no_self_use.rs @@ -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 @@ -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 { @@ -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") } } diff --git a/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR6301_no_self_use.py.snap b/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR6301_no_self_use.py.snap index 3b45a59ad686a..85675b6d9fa87 100644 --- a/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR6301_no_self_use.py.snap +++ b/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR6301_no_self_use.py.snap @@ -1,7 +1,7 @@ --- 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] @@ -9,7 +9,7 @@ no_self_use.py:7:28: PLR6301 Method `developer_greeting` could be a function or 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 | @@ -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 |