mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 10:22:24 +00:00
Allow private accesses on super calls (#2815)
This commit is contained in:
parent
b8835c2e35
commit
9ddd5e4cfe
2 changed files with 16 additions and 8 deletions
|
@ -38,13 +38,13 @@ class Foo(metaclass=BazMeta):
|
|||
return self.bar
|
||||
|
||||
def public_func(self):
|
||||
pass
|
||||
super().public_func()
|
||||
|
||||
def _private_func(self):
|
||||
pass
|
||||
super()._private_func()
|
||||
|
||||
def __really_private_func(self, arg):
|
||||
pass
|
||||
super().__really_private_func(arg)
|
||||
|
||||
|
||||
foo = Foo()
|
||||
|
|
|
@ -21,15 +21,23 @@ impl Violation for PrivateMemberAccess {
|
|||
}
|
||||
}
|
||||
|
||||
const VALID_IDS: [&str; 3] = ["self", "cls", "mcs"];
|
||||
|
||||
/// SLF001
|
||||
pub fn private_member_access(checker: &mut Checker, expr: &Expr) {
|
||||
if let ExprKind::Attribute { value, attr, .. } = &expr.node {
|
||||
if !attr.ends_with("__") && (attr.starts_with('_') || attr.starts_with("__")) {
|
||||
let call_path = collect_call_path(value);
|
||||
if VALID_IDS.iter().any(|id| call_path.as_slice() == [*id]) {
|
||||
return;
|
||||
if let ExprKind::Call { func, .. } = &value.node {
|
||||
let call_path = collect_call_path(func);
|
||||
if call_path.as_slice() == ["super"] {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
let call_path = collect_call_path(value);
|
||||
if call_path.as_slice() == ["self"]
|
||||
|| call_path.as_slice() == ["cls"]
|
||||
|| call_path.as_slice() == ["mcs"]
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue