Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid PLE0237 for property with setter #11377

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,19 @@ def __init__(self, name, middle_name):

def setup(self):
pass


# https://github.com/astral-sh/ruff/issues/11358
class Foo:
__slots__ = ("bar",)

def __init__(self):
self.qux = 2

@property
def qux(self):
return self.bar * 2

@qux.setter
def qux(self, value):
self.bar = value / 2
22 changes: 22 additions & 0 deletions crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,28 @@ fn is_attributes_not_in_slots(body: &[Stmt]) -> Vec<AttributeAssignment> {
return vec![];
}

// And, collect all the property name with setter.
for statement in body {
let Stmt::FunctionDef(ast::StmtFunctionDef { decorator_list, .. }) = statement else {
continue;
};

for decorator in decorator_list {
let Some(ast::ExprAttribute { value, attr, .. }) =
decorator.expression.as_attribute_expr()
else {
continue;
};

if attr == "setter" {
let Some(ast::ExprName { id, .. }) = value.as_name_expr() else {
continue;
};
slots.insert(id.as_str());
}
}
}

// Second, find any assignments that aren't included in `__slots__`.
let mut assignments = vec![];
for statement in body {
Expand Down
Loading