From 0753968ef328282edfcb37dfbde073cd896a3d5e Mon Sep 17 00:00:00 2001 From: yataka <33962896+takaya0@users.noreply.github.com> Date: Mon, 15 Jan 2024 23:37:19 +0900 Subject: [PATCH] add the "__prepare__" method to the list of recognized dunder method (#9529) ## Summary Closes #9508 . Add `__prepare__` method to dunder method list in `is_known_dunder_method`. ## Test Plan 1. add "__prepare__" method to `Apple` class in crates/ruff_linter/resources/test/fixtures/pylint/bad_dunder_method_name.py. 2. run `cargo test` --- .../resources/test/fixtures/pylint/bad_dunder_method_name.py | 4 ++++ crates/ruff_linter/src/rules/pylint/helpers.rs | 1 + 2 files changed, 5 insertions(+) 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 5032f42ff1..f8aaddbf96 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 @@ -87,6 +87,10 @@ class Apples: def __special_custom_magic__(self): pass + @classmethod + def __prepare__(): + pass + def __foo_bar__(): # this is not checked by the [bad-dunder-name] rule ... diff --git a/crates/ruff_linter/src/rules/pylint/helpers.rs b/crates/ruff_linter/src/rules/pylint/helpers.rs index 75fb3a69fe..de867b3135 100644 --- a/crates/ruff_linter/src/rules/pylint/helpers.rs +++ b/crates/ruff_linter/src/rules/pylint/helpers.rs @@ -289,6 +289,7 @@ pub(super) fn is_known_dunder_method(method: &str) -> bool { | "__pos__" | "__post_init__" | "__pow__" + | "__prepare__" | "__radd__" | "__rand__" | "__rdivmod__"