Catch RET504 usages via decorators (#3395)

This commit is contained in:
Charlie Marsh 2023-03-07 19:38:01 -05:00 committed by GitHub
parent 3f04def3a5
commit d9dfec30eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 2 deletions

View File

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

View File

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