Skip to content

Commit

Permalink
Move remaining lambda rule to deferred pass (#8098)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored Oct 20, 2023
1 parent b107204 commit ae41d6f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ruff_python_ast::Expr;

use crate::checkers::ast::Checker;
use crate::codes::Rule;
use crate::rules::pylint;
use crate::rules::{flake8_pie, pylint};

/// Run lint rules over all deferred lambdas in the [`SemanticModel`].
pub(crate) fn deferred_lambdas(checker: &mut Checker) {
Expand All @@ -18,6 +18,9 @@ pub(crate) fn deferred_lambdas(checker: &mut Checker) {
if checker.enabled(Rule::UnnecessaryLambda) {
pylint::rules::unnecessary_lambda(checker, lambda);
}
if checker.enabled(Rule::ReimplementedListBuiltin) {
flake8_pie::rules::reimplemented_list_builtin(checker, lambda);
}
}
}
}
11 changes: 0 additions & 11 deletions crates/ruff_linter/src/checkers/ast/analyze/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1267,17 +1267,6 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) {
}
}
}
Expr::Lambda(
lambda @ ast::ExprLambda {
parameters: _,
body: _,
range: _,
},
) => {
if checker.enabled(Rule::ReimplementedListBuiltin) {
flake8_pie::rules::reimplemented_list_builtin(checker, lambda);
}
}
Expr::IfExp(ast::ExprIfExp {
test,
body,
Expand Down
26 changes: 13 additions & 13 deletions crates/ruff_linter/src/checkers/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1834,15 +1834,15 @@ impl<'a> Checker<'a> {
for snapshot in deferred_functions {
self.semantic.restore(snapshot);

if let Stmt::FunctionDef(ast::StmtFunctionDef {
let Stmt::FunctionDef(ast::StmtFunctionDef {
body, parameters, ..
}) = self.semantic.current_statement()
{
self.visit_parameters(parameters);
self.visit_body(body);
} else {
else {
unreachable!("Expected Stmt::FunctionDef")
}
};

self.visit_parameters(parameters);
self.visit_body(body);
}
}
self.semantic.restore(snapshot);
Expand All @@ -1856,19 +1856,19 @@ impl<'a> Checker<'a> {
for snapshot in lambdas {
self.semantic.restore(snapshot);

if let Some(Expr::Lambda(ast::ExprLambda {
let Some(Expr::Lambda(ast::ExprLambda {
parameters,
body,
range: _,
})) = self.semantic.current_expression()
{
if let Some(parameters) = parameters {
self.visit_parameters(parameters);
}
self.visit_expr(body);
} else {
else {
unreachable!("Expected Expr::Lambda");
};

if let Some(parameters) = parameters {
self.visit_parameters(parameters);
}
self.visit_expr(body);

deferred.push(snapshot);
}
Expand Down

0 comments on commit ae41d6f

Please sign in to comment.