From f8f56186b3d095eb2aa8839c44aba588bd8d5aee Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 11 Mar 2024 15:48:56 -0700 Subject: [PATCH] [`pylint`] Avoid false-positive slot non-assignment for `__dict__` (`PLE0237`) (#10348) Closes https://github.com/astral-sh/ruff/issues/10306. --- .../test/fixtures/pylint/non_slot_assignment.py | 12 ++++++++++++ .../src/rules/pylint/rules/non_slot_assignment.rs | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/ruff_linter/resources/test/fixtures/pylint/non_slot_assignment.py b/crates/ruff_linter/resources/test/fixtures/pylint/non_slot_assignment.py index c1ced1bbb80b1..cef5b6dcce1df 100644 --- a/crates/ruff_linter/resources/test/fixtures/pylint/non_slot_assignment.py +++ b/crates/ruff_linter/resources/test/fixtures/pylint/non_slot_assignment.py @@ -54,3 +54,15 @@ def __init__(self, name, middle_name): def setup(self): pass + + +class StudentF(object): + __slots__ = ("name", "__dict__") + + def __init__(self, name, middle_name): + self.name = name + self.middle_name = middle_name # [assigning-non-slot] + self.setup() + + def setup(self): + pass diff --git a/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs b/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs index 2371a9b30327c..bd2bf426bf2c3 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs @@ -142,7 +142,7 @@ fn is_attributes_not_in_slots(body: &[Stmt]) -> Vec { } } - if slots.is_empty() { + if slots.is_empty() || slots.contains("__dict__") { return vec![]; }