Visit NamedExpr values before targets (#2484)

This commit is contained in:
Charlie Marsh 2023-02-02 12:21:58 -05:00 committed by GitHub
parent ac41c33d1f
commit a0df78cb7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View File

@ -86,3 +86,11 @@ def f():
open("") as ((this, that)),
):
print("hello")
def f():
exponential, base_multiplier = 1, 2
hash_map = {
(exponential := (exponential * base_multiplier) % 3): i + 1 for i in range(2)
}
return hash_map

View File

@ -266,8 +266,8 @@ pub fn walk_expr<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, expr: &'a Expr) {
}
}
ExprKind::NamedExpr { target, value } => {
visitor.visit_expr(target);
visitor.visit_expr(value);
visitor.visit_expr(target);
}
ExprKind::BinOp { left, op, right } => {
visitor.visit_expr(left);

View File

@ -4449,7 +4449,7 @@ impl<'a> Checker<'a> {
fn check_deferred_assignments(&mut self) {
self.deferred_assignments.reverse();
while let Some((scopes, _parents)) = self.deferred_assignments.pop() {
while let Some((scopes, ..)) = self.deferred_assignments.pop() {
let scope_index = scopes[scopes.len() - 1];
let parent_scope_index = scopes[scopes.len() - 2];
if self.settings.rules.enabled(&Rule::UnusedVariable) {