mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
Avoid PLE0237
for property with setter (#11377)
## Summary Should this consider the decorator only if the name is actually a property or is the logic in this PR correct? fixes: #11358 ## Test Plan Add test case.
This commit is contained in:
parent
d835b3e218
commit
0fc6cf9bee
2 changed files with 38 additions and 0 deletions
|
@ -66,3 +66,19 @@ class StudentF(object):
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
pass
|
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
|
||||||
|
|
|
@ -147,6 +147,28 @@ fn is_attributes_not_in_slots(body: &[Stmt]) -> Vec<AttributeAssignment> {
|
||||||
return vec![];
|
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__`.
|
// Second, find any assignments that aren't included in `__slots__`.
|
||||||
let mut assignments = vec![];
|
let mut assignments = vec![];
|
||||||
for statement in body {
|
for statement in body {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue