@@ -149,28 +149,7 @@ def ast3_parse(
149149 )
150150
151151
152- if sys .version_info >= (3 , 10 ):
153- Match = ast3 .Match
154- MatchValue = ast3 .MatchValue
155- MatchSingleton = ast3 .MatchSingleton
156- MatchSequence = ast3 .MatchSequence
157- MatchStar = ast3 .MatchStar
158- MatchMapping = ast3 .MatchMapping
159- MatchClass = ast3 .MatchClass
160- MatchAs = ast3 .MatchAs
161- MatchOr = ast3 .MatchOr
162- AstNode = Union [ast3 .expr , ast3 .stmt , ast3 .pattern , ast3 .ExceptHandler ]
163- else :
164- Match = Any
165- MatchValue = Any
166- MatchSingleton = Any
167- MatchSequence = Any
168- MatchStar = Any
169- MatchMapping = Any
170- MatchClass = Any
171- MatchAs = Any
172- MatchOr = Any
173- AstNode = Union [ast3 .expr , ast3 .stmt , ast3 .ExceptHandler ]
152+ AstNode = ast3 .expr | ast3 .stmt | ast3 .pattern | ast3 .ExceptHandler
174153
175154if sys .version_info >= (3 , 11 ):
176155 TryStar = ast3 .TryStar
@@ -1779,7 +1758,7 @@ def visit_Slice(self, n: ast3.Slice) -> SliceExpr:
17791758 return self .set_line (e , n )
17801759
17811760 # Match(expr subject, match_case* cases) # python 3.10 and later
1782- def visit_Match (self , n : Match ) -> MatchStmt :
1761+ def visit_Match (self , n : ast3 . Match ) -> MatchStmt :
17831762 node = MatchStmt (
17841763 self .visit (n .subject ),
17851764 [self .visit (c .pattern ) for c in n .cases ],
@@ -1788,23 +1767,23 @@ def visit_Match(self, n: Match) -> MatchStmt:
17881767 )
17891768 return self .set_line (node , n )
17901769
1791- def visit_MatchValue (self , n : MatchValue ) -> ValuePattern :
1770+ def visit_MatchValue (self , n : ast3 . MatchValue ) -> ValuePattern :
17921771 node = ValuePattern (self .visit (n .value ))
17931772 return self .set_line (node , n )
17941773
1795- def visit_MatchSingleton (self , n : MatchSingleton ) -> SingletonPattern :
1774+ def visit_MatchSingleton (self , n : ast3 . MatchSingleton ) -> SingletonPattern :
17961775 node = SingletonPattern (n .value )
17971776 return self .set_line (node , n )
17981777
1799- def visit_MatchSequence (self , n : MatchSequence ) -> SequencePattern :
1778+ def visit_MatchSequence (self , n : ast3 . MatchSequence ) -> SequencePattern :
18001779 patterns = [self .visit (p ) for p in n .patterns ]
18011780 stars = [p for p in patterns if isinstance (p , StarredPattern )]
18021781 assert len (stars ) < 2
18031782
18041783 node = SequencePattern (patterns )
18051784 return self .set_line (node , n )
18061785
1807- def visit_MatchStar (self , n : MatchStar ) -> StarredPattern :
1786+ def visit_MatchStar (self , n : ast3 . MatchStar ) -> StarredPattern :
18081787 if n .name is None :
18091788 node = StarredPattern (None )
18101789 else :
@@ -1813,7 +1792,7 @@ def visit_MatchStar(self, n: MatchStar) -> StarredPattern:
18131792
18141793 return self .set_line (node , n )
18151794
1816- def visit_MatchMapping (self , n : MatchMapping ) -> MappingPattern :
1795+ def visit_MatchMapping (self , n : ast3 . MatchMapping ) -> MappingPattern :
18171796 keys = [self .visit (k ) for k in n .keys ]
18181797 values = [self .visit (v ) for v in n .patterns ]
18191798
@@ -1825,7 +1804,7 @@ def visit_MatchMapping(self, n: MatchMapping) -> MappingPattern:
18251804 node = MappingPattern (keys , values , rest )
18261805 return self .set_line (node , n )
18271806
1828- def visit_MatchClass (self , n : MatchClass ) -> ClassPattern :
1807+ def visit_MatchClass (self , n : ast3 . MatchClass ) -> ClassPattern :
18291808 class_ref = self .visit (n .cls )
18301809 assert isinstance (class_ref , RefExpr )
18311810 positionals = [self .visit (p ) for p in n .patterns ]
@@ -1836,7 +1815,7 @@ def visit_MatchClass(self, n: MatchClass) -> ClassPattern:
18361815 return self .set_line (node , n )
18371816
18381817 # MatchAs(expr pattern, identifier name)
1839- def visit_MatchAs (self , n : MatchAs ) -> AsPattern :
1818+ def visit_MatchAs (self , n : ast3 . MatchAs ) -> AsPattern :
18401819 if n .name is None :
18411820 name = None
18421821 else :
@@ -1846,7 +1825,7 @@ def visit_MatchAs(self, n: MatchAs) -> AsPattern:
18461825 return self .set_line (node , n )
18471826
18481827 # MatchOr(expr* pattern)
1849- def visit_MatchOr (self , n : MatchOr ) -> OrPattern :
1828+ def visit_MatchOr (self , n : ast3 . MatchOr ) -> OrPattern :
18501829 node = OrPattern ([self .visit (pattern ) for pattern in n .patterns ])
18511830 return self .set_line (node , n )
18521831
0 commit comments