@@ -396,6 +396,7 @@ def __init__(
396396 # 'C' for class, 'D' for function signature, 'F' for function, 'L' for lambda
397397 self .class_and_function_stack : list [Literal ["C" , "D" , "F" , "L" ]] = []
398398 self .imports : list [ImportBase ] = []
399+ self .match_stmt_subject = False
399400
400401 self .options = options
401402 self .is_stub = is_stub
@@ -1758,7 +1759,7 @@ def visit_Name(self, n: Name) -> NameExpr:
17581759 # List(expr* elts, expr_context ctx)
17591760 def visit_List (self , n : ast3 .List ) -> ListExpr | TupleExpr :
17601761 expr_list : list [Expression ] = [self .visit (e ) for e in n .elts ]
1761- if isinstance (n .ctx , ast3 .Store ):
1762+ if isinstance (n .ctx , ast3 .Store ) or self . match_stmt_subject :
17621763 # [x, y] = z and (x, y) = z means exactly the same thing
17631764 e : ListExpr | TupleExpr = TupleExpr (expr_list )
17641765 else :
@@ -1779,8 +1780,11 @@ def visit_Slice(self, n: ast3.Slice) -> SliceExpr:
17791780
17801781 # Match(expr subject, match_case* cases) # python 3.10 and later
17811782 def visit_Match (self , n : Match ) -> MatchStmt :
1783+ self .match_stmt_subject = True
1784+ subject = self .visit (n .subject )
1785+ self .match_stmt_subject = False
17821786 node = MatchStmt (
1783- self . visit ( n . subject ) ,
1787+ subject ,
17841788 [self .visit (c .pattern ) for c in n .cases ],
17851789 [self .visit (c .guard ) for c in n .cases ],
17861790 [self .as_required_block (c .body ) for c in n .cases ],
0 commit comments