@@ -1034,52 +1034,49 @@ def visit_ImportFrom(self, node: ast.ImportFrom) -> ast.ImportFrom:
10341034 )
10351035 return node
10361036
1037- if sys .version_info >= (3 , 10 ):
1038- # Match statements were introduced in Python 3.10
1039- #
1040- # Top-level match statements are awkward in marimo --- at parse-time,
1041- # we have to register all names in every case/pattern as globals (since
1042- # we don't know the value of the match subject), even though only a
1043- # subset of the names will be bound at runtime. For this reason, in
1044- # marimo, match statements should really only be used in local scopes.
1045- def visit_MatchAs (self , node : ast .MatchAs ) -> ast .MatchAs :
1046- if node .name is not None :
1047- node .name = self ._if_local_then_mangle (node .name )
1048- self ._define (
1049- node ,
1050- node .name ,
1051- VariableData (kind = "variable" ),
1052- )
1053- if node .pattern is not None :
1054- # pattern may contain additional MatchAs statements in it
1055- self .visit (node .pattern )
1056- return node
1037+ # Match statements were introduced in Python 3.10
1038+ #
1039+ # Top-level match statements are awkward in marimo --- at parse-time,
1040+ # we have to register all names in every case/pattern as globals (since
1041+ # we don't know the value of the match subject), even though only a
1042+ # subset of the names will be bound at runtime. For this reason, in
1043+ # marimo, match statements should really only be used in local scopes.
1044+ def visit_MatchAs (self , node : ast .MatchAs ) -> ast .MatchAs :
1045+ if node .name is not None :
1046+ node .name = self ._if_local_then_mangle (node .name )
1047+ self ._define (
1048+ node ,
1049+ node .name ,
1050+ VariableData (kind = "variable" ),
1051+ )
1052+ if node .pattern is not None :
1053+ # pattern may contain additional MatchAs statements in it
1054+ self .visit (node .pattern )
1055+ return node
10571056
1058- def visit_MatchMapping (
1059- self , node : ast .MatchMapping
1060- ) -> ast .MatchMapping :
1061- if node .rest is not None :
1062- node .rest = self ._if_local_then_mangle (node .rest )
1063- self ._define (
1064- node ,
1065- node .rest ,
1066- VariableData (kind = "variable" ),
1067- )
1068- for key in node .keys :
1069- self .visit (key )
1070- for pattern in node .patterns :
1071- self .visit (pattern )
1072- return node
1057+ def visit_MatchMapping (self , node : ast .MatchMapping ) -> ast .MatchMapping :
1058+ if node .rest is not None :
1059+ node .rest = self ._if_local_then_mangle (node .rest )
1060+ self ._define (
1061+ node ,
1062+ node .rest ,
1063+ VariableData (kind = "variable" ),
1064+ )
1065+ for key in node .keys :
1066+ self .visit (key )
1067+ for pattern in node .patterns :
1068+ self .visit (pattern )
1069+ return node
10731070
1074- def visit_MatchStar (self , node : ast .MatchStar ) -> ast .MatchStar :
1075- if node .name is not None :
1076- node .name = self ._if_local_then_mangle (node .name )
1077- self ._define (
1078- node ,
1079- node .name ,
1080- VariableData (kind = "variable" ),
1081- )
1082- return node
1071+ def visit_MatchStar (self , node : ast .MatchStar ) -> ast .MatchStar :
1072+ if node .name is not None :
1073+ node .name = self ._if_local_then_mangle (node .name )
1074+ self ._define (
1075+ node ,
1076+ node .name ,
1077+ VariableData (kind = "variable" ),
1078+ )
1079+ return node
10831080
10841081 if sys .version_info >= (3 , 12 ):
10851082
0 commit comments