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:
Dhruv Manilawala 2024-05-13 05:53:00 +05:30 committed by GitHub
parent d835b3e218
commit 0fc6cf9bee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 0 deletions

View file

@ -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 {