From 9d1bd7a8a776d0f44e7039de2be66040cb938fd4 Mon Sep 17 00:00:00 2001 From: Lucas Vieira dos Santos Date: Wed, 4 Sep 2024 08:23:08 +0200 Subject: [PATCH] [pylint] removed dunder methods in Python 3 (PLW3201) (#13194) Co-authored-by: Micha Reiser --- .../fixtures/pylint/bad_dunder_method_name.py | 3 +++ .../pylint/rules/bad_dunder_method_name.rs | 6 +++--- ...ts__PLW3201_bad_dunder_method_name.py.snap | 20 ++++++++++++------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/crates/ruff_linter/resources/test/fixtures/pylint/bad_dunder_method_name.py b/crates/ruff_linter/resources/test/fixtures/pylint/bad_dunder_method_name.py index cf264981284c2..32c8c4c44d887 100644 --- a/crates/ruff_linter/resources/test/fixtures/pylint/bad_dunder_method_name.py +++ b/crates/ruff_linter/resources/test/fixtures/pylint/bad_dunder_method_name.py @@ -94,6 +94,9 @@ def __prepare__(): def __mro_entries__(self, bases): pass + # Removed with Python 3 + def __unicode__(self): + pass def __foo_bar__(): # this is not checked by the [bad-dunder-name] rule ... diff --git a/crates/ruff_linter/src/rules/pylint/rules/bad_dunder_method_name.rs b/crates/ruff_linter/src/rules/pylint/rules/bad_dunder_method_name.rs index 2812cf214aab5..95dc16ab9cd6f 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/bad_dunder_method_name.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/bad_dunder_method_name.rs @@ -8,10 +8,10 @@ use crate::checkers::ast::Checker; use crate::rules::pylint::helpers::is_known_dunder_method; /// ## What it does -/// Checks for misspelled and unknown dunder names in method definitions. +/// Checks for dunder methods that have no special meaning in Python 3. /// /// ## Why is this bad? -/// Misspelled dunder name methods may cause your code to not function +/// Misspelled or no longer supported dunder name methods may cause your code to not function /// as expected. /// /// Since dunder methods are associated with customizing the behavior @@ -51,7 +51,7 @@ impl Violation for BadDunderMethodName { #[derive_message_formats] fn message(&self) -> String { let BadDunderMethodName { name } = self; - format!("Bad or misspelled dunder method name `{name}`") + format!("Dunder method `{name}` has no special meaning in Python 3") } } diff --git a/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLW3201_bad_dunder_method_name.py.snap b/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLW3201_bad_dunder_method_name.py.snap index fb777d47a8fd1..a98abee052372 100644 --- a/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLW3201_bad_dunder_method_name.py.snap +++ b/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLW3201_bad_dunder_method_name.py.snap @@ -1,7 +1,7 @@ --- source: crates/ruff_linter/src/rules/pylint/mod.rs --- -bad_dunder_method_name.py:5:9: PLW3201 Bad or misspelled dunder method name `_init_` +bad_dunder_method_name.py:5:9: PLW3201 Dunder method `_init_` has no special meaning in Python 3 | 4 | class Apples: 5 | def _init_(self): # [bad-dunder-name] @@ -9,7 +9,7 @@ bad_dunder_method_name.py:5:9: PLW3201 Bad or misspelled dunder method name `_in 6 | pass | -bad_dunder_method_name.py:8:9: PLW3201 Bad or misspelled dunder method name `__hello__` +bad_dunder_method_name.py:8:9: PLW3201 Dunder method `__hello__` has no special meaning in Python 3 | 6 | pass 7 | @@ -18,7 +18,7 @@ bad_dunder_method_name.py:8:9: PLW3201 Bad or misspelled dunder method name `__h 9 | print("hello") | -bad_dunder_method_name.py:11:9: PLW3201 Bad or misspelled dunder method name `__init_` +bad_dunder_method_name.py:11:9: PLW3201 Dunder method `__init_` has no special meaning in Python 3 | 9 | print("hello") 10 | @@ -28,7 +28,7 @@ bad_dunder_method_name.py:11:9: PLW3201 Bad or misspelled dunder method name `__ 13 | pass | -bad_dunder_method_name.py:15:9: PLW3201 Bad or misspelled dunder method name `_init_` +bad_dunder_method_name.py:15:9: PLW3201 Dunder method `_init_` has no special meaning in Python 3 | 13 | pass 14 | @@ -38,7 +38,7 @@ bad_dunder_method_name.py:15:9: PLW3201 Bad or misspelled dunder method name `_i 17 | pass | -bad_dunder_method_name.py:19:9: PLW3201 Bad or misspelled dunder method name `___neg__` +bad_dunder_method_name.py:19:9: PLW3201 Dunder method `___neg__` has no special meaning in Python 3 | 17 | pass 18 | @@ -48,7 +48,7 @@ bad_dunder_method_name.py:19:9: PLW3201 Bad or misspelled dunder method name `__ 21 | pass | -bad_dunder_method_name.py:23:9: PLW3201 Bad or misspelled dunder method name `__inv__` +bad_dunder_method_name.py:23:9: PLW3201 Dunder method `__inv__` has no special meaning in Python 3 | 21 | pass 22 | @@ -58,4 +58,10 @@ bad_dunder_method_name.py:23:9: PLW3201 Bad or misspelled dunder method name `__ 25 | pass | - +bad_dunder_method_name.py:98:9: PLW3201 Dunder method `__unicode__` has no special meaning in Python 3 + | +97 | # Removed with Python 3 +98 | def __unicode__(self): + | ^^^^^^^^^^^ PLW3201 +99 | pass + |