@@ -1010,20 +1010,16 @@ def visit_BoolOp(self, boolop: ast.BoolOp) -> tuple[ast.Name, str]:
10101010 # cond is set in a prior loop iteration below
10111011 self .expl_stmts .append (ast .If (cond , fail_inner , [])) # noqa: F821
10121012 self .expl_stmts = fail_inner
1013- # Check if the left operand is a ast.NamedExpr and the value has already been visited
1014- if (
1015- isinstance (v , ast .Compare )
1016- and isinstance (v .left , ast .NamedExpr )
1017- and v .left .target .id
1018- in [
1019- ast_expr .id
1020- for ast_expr in boolop .values [:i ]
1021- if hasattr (ast_expr , "id" )
1022- ]
1023- ):
1024- pytest_temp = self .variable ()
1025- self .variables_overwrite [self .scope ][v .left .target .id ] = v .left # type:ignore[assignment]
1026- v .left .target .id = pytest_temp
1013+ match v :
1014+ # Check if the left operand is an ast.NamedExpr and the value has already been visited
1015+ case ast .Compare (left = ast .NamedExpr (target = ast .Name (id = target_id ))):
1016+ if target_id in [
1017+ e .id for e in boolop .values [:i ] if hasattr (e , "id" )
1018+ ]:
1019+ pytest_temp = self .variable ()
1020+ self .variables_overwrite [self .scope ][target_id ] = v .left # type:ignore[assignment]
1021+ # mypy's false positive, we're checking that the 'target' attribute exists.
1022+ v .left .target .id = pytest_temp # type:ignore[attr-defined]
10271023 self .push_format_context ()
10281024 res , expl = self .visit (v )
10291025 body .append (ast .Assign ([ast .Name (res_var , ast .Store ())], res ))
0 commit comments