mirror of https://github.com/astral-sh/ruff
Catch RET504 usages via decorators (#3395)
This commit is contained in:
parent
3f04def3a5
commit
d9dfec30eb
|
|
@ -260,3 +260,23 @@ def nonlocal_assignment():
|
||||||
nonlocal X
|
nonlocal X
|
||||||
X = 1
|
X = 1
|
||||||
return X
|
return X
|
||||||
|
|
||||||
|
|
||||||
|
def decorator() -> Flask:
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@app.route('/hello')
|
||||||
|
def hello() -> str:
|
||||||
|
"""Hello endpoint."""
|
||||||
|
return 'Hello, World!'
|
||||||
|
|
||||||
|
return app
|
||||||
|
|
||||||
|
|
||||||
|
def default():
|
||||||
|
y = 1
|
||||||
|
|
||||||
|
def f(x = y) -> X:
|
||||||
|
return x
|
||||||
|
|
||||||
|
return y
|
||||||
|
|
|
||||||
|
|
@ -66,8 +66,26 @@ impl<'a> Visitor<'a> for ReturnVisitor<'a> {
|
||||||
.non_locals
|
.non_locals
|
||||||
.extend(names.iter().map(String::as_str));
|
.extend(names.iter().map(String::as_str));
|
||||||
}
|
}
|
||||||
StmtKind::FunctionDef { .. } | StmtKind::AsyncFunctionDef { .. } => {
|
StmtKind::FunctionDef {
|
||||||
// Don't recurse.
|
decorator_list,
|
||||||
|
args,
|
||||||
|
returns,
|
||||||
|
..
|
||||||
|
}
|
||||||
|
| StmtKind::AsyncFunctionDef {
|
||||||
|
decorator_list,
|
||||||
|
args,
|
||||||
|
returns,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
// Don't recurse into the body, but visit the decorators, etc.
|
||||||
|
for expr in decorator_list {
|
||||||
|
visitor::walk_expr(self, expr);
|
||||||
|
}
|
||||||
|
if let Some(returns) = returns {
|
||||||
|
visitor::walk_expr(self, returns);
|
||||||
|
}
|
||||||
|
visitor::walk_arguments(self, args);
|
||||||
}
|
}
|
||||||
StmtKind::Return { value } => {
|
StmtKind::Return { value } => {
|
||||||
self.stack
|
self.stack
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue