Support PEP 562 (#841)
This commit is contained in:
21
resources/test/fixtures/N807.py
vendored
21
resources/test/fixtures/N807.py
vendored
@@ -10,6 +10,27 @@ def good__():
|
||||
pass
|
||||
|
||||
|
||||
def nested():
|
||||
def __bad__():
|
||||
pass
|
||||
|
||||
def __good():
|
||||
pass
|
||||
|
||||
def good__():
|
||||
pass
|
||||
|
||||
|
||||
class Class:
|
||||
def __good__(self):
|
||||
pass
|
||||
|
||||
|
||||
# https://peps.python.org/pep-0562/
|
||||
def __getattr__(name):
|
||||
pass
|
||||
|
||||
|
||||
# https://peps.python.org/pep-0562/
|
||||
def __dir__():
|
||||
pass
|
||||
|
||||
@@ -132,6 +132,11 @@ pub fn dunder_function_name(scope: &Scope, stmt: &Stmt, name: &str) -> Option<Ch
|
||||
return None;
|
||||
}
|
||||
if name.starts_with("__") && name.ends_with("__") {
|
||||
// Allowed under PEP 562 (https://peps.python.org/pep-0562/).
|
||||
if matches!(scope.kind, ScopeKind::Module) && (name == "__getattr__" || name == "__dir__") {
|
||||
return None;
|
||||
}
|
||||
|
||||
return Some(Check::new(
|
||||
CheckKind::DunderFunctionName,
|
||||
Range::from_located(stmt),
|
||||
|
||||
@@ -10,4 +10,12 @@ expression: checks
|
||||
row: 5
|
||||
column: 0
|
||||
fix: ~
|
||||
- kind: DunderFunctionName
|
||||
location:
|
||||
row: 14
|
||||
column: 4
|
||||
end_location:
|
||||
row: 17
|
||||
column: 4
|
||||
fix: ~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user