mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
[ruff
] Avoid treating named expressions as static keys (RUF011
) (#9494)
Closes https://github.com/astral-sh/ruff/issues/9487.
This commit is contained in:
parent
7504bf347b
commit
009430e034
5 changed files with 84 additions and 49 deletions
|
@ -914,6 +914,27 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// A [`Visitor`] to collect all stored [`Expr::Name`] nodes in an AST.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct StoredNameFinder<'a> {
|
||||
/// A map from identifier to defining expression.
|
||||
pub names: FxHashMap<&'a str, &'a ast::ExprName>,
|
||||
}
|
||||
|
||||
impl<'a, 'b> Visitor<'b> for StoredNameFinder<'a>
|
||||
where
|
||||
'b: 'a,
|
||||
{
|
||||
fn visit_expr(&mut self, expr: &'a Expr) {
|
||||
if let Expr::Name(name) = expr {
|
||||
if name.ctx.is_store() {
|
||||
self.names.insert(&name.id, name);
|
||||
}
|
||||
}
|
||||
crate::visitor::walk_expr(self, expr);
|
||||
}
|
||||
}
|
||||
|
||||
/// A [`StatementVisitor`] that collects all `return` statements in a function or method.
|
||||
#[derive(Default)]
|
||||
pub struct ReturnStatementVisitor<'a> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue