From 8304c417144f8e53aa2f143e36ba39f212062570 Mon Sep 17 00:00:00 2001 From: Spencer Brown Date: Wed, 25 Oct 2023 15:03:44 +1000 Subject: [PATCH] [`pylint`] Add buffer methods to `bad-dunder-method-name` (`PLW3201`) exclusions (#8190) ## Summary Python 3.12 added the `__buffer__()`/`__release_buffer_()` special methods, which are incorrectly flagged as invalid dunder methods by `PLW3201`. ## Test Plan Added definitions to the test suite, and confirmed they failed without the fix and are ignored after the fix was done. --- .../test/fixtures/pylint/bad_dunder_method_name.py | 7 +++++++ .../src/rules/pylint/rules/bad_dunder_method_name.rs | 2 ++ 2 files changed, 9 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 86c9081b475b4..2040086e5d930 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 @@ -49,6 +49,13 @@ def __private_method(self): def __doc__(self): return "Docstring" + # Added in Python 3.12 + def __buffer__(self): + return memoryview(b'') + + def __release_buffer__(self, buf): + pass + # Allow dunder methods recommended by attrs. def __attrs_post_init__(self): pass 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 0ea5001d54053..b4a30f54aaa90 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 @@ -88,6 +88,7 @@ fn is_known_dunder_method(method: &str) -> bool { | "__attrs_pre_init__" | "__await__" | "__bool__" + | "__buffer__" | "__bytes__" | "__call__" | "__ceil__" @@ -166,6 +167,7 @@ fn is_known_dunder_method(method: &str) -> bool { | "__rdivmod__" | "__reduce__" | "__reduce_ex__" + | "__release_buffer__" | "__repr__" | "__reversed__" | "__rfloordiv__"