From c4ea52a05e9a94ac19d7209fc68dd2b26755b84f Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Tue, 17 Oct 2023 09:54:58 -0400 Subject: [PATCH] Avoid flagging bad-dunder-method-name for _ --- .../resources/test/fixtures/pylint/bad_dunder_method_name.py | 4 ++++ .../src/rules/pylint/rules/bad_dunder_method_name.rs | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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 468e86f2f3c28..86c9081b475b4 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 @@ -68,6 +68,10 @@ def __html__(self): def _missing_(cls, value): pass + # Allow anonymous functions. + def _(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 98c05d6554b9b..0ea5001d54053 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 @@ -54,7 +54,7 @@ pub(crate) fn bad_dunder_method_name(checker: &mut Checker, class_body: &[Stmt]) .iter() .filter_map(ruff_python_ast::Stmt::as_function_def_stmt) .filter(|method| { - if is_known_dunder_method(&method.name) { + if is_known_dunder_method(&method.name) || matches!(method.name.as_str(), "_") { return false; } method.name.starts_with('_') && method.name.ends_with('_')