Skip to content

Commit

Permalink
Bugfix + tests for MatchOr expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
soupytwist committed Feb 26, 2024
1 parent 9af5611 commit 3fdf178
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
8 changes: 3 additions & 5 deletions pasta/base/annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,12 +1164,10 @@ def visit_MatchAs(self, node):

@expression
def visit_MatchOr(self, node):
for pattern in node.patterns:
self.visit(node.pattern)
for i, pattern in enumerate(node.patterns):
self.visit(pattern)
if pattern is not node.patterns[-1]:
self.attr(
node, 'comma_%d' % arg_i, [self.ws, ',', self.ws], default=', ')
self.optional_token(node, 'extracomma', ',', allow_whitespace_prefix=True)
self.attr(node, 'bar_%d' % i, [self.ws, '|', self.ws], default=' | ')

@expression
def visit_Name(self, node):
Expand Down
19 changes: 19 additions & 0 deletions testdata/ast/golden/3.11/match_as_or.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(-1, -1) Module prefix=|@@indent@@| suffix=|@@indent@@| indent=||
(1, 0) Match prefix=|| suffix=|| indent=||
(1, 6) Name a prefix=|| suffix=|| indent=||
(-1, -1) match_case prefix=|@@indent@@| suffix=|| indent=| |
(-1, -1) match_case prefix=|@@indent@@| suffix=|| indent=| |
(-1, -1) Load prefix=|| suffix=|| indent=||
(2, 7) MatchAs c prefix=|| suffix=|| indent=| |
(3, 4) Expr prefix=|@@indent@@| suffix=|\n| indent=| |
(4, 7) MatchOr prefix=|| suffix=|| indent=| |
(5, 4) Expr prefix=|@@indent@@| suffix=|\n| indent=| |
(2, 7) MatchSequence prefix=|| suffix=| | indent=| |
(3, 4) Name d prefix=|| suffix=|| indent=| |
(4, 7) MatchSequence prefix=|| suffix=| | indent=| |
(4, 14) MatchAs f prefix=|(| suffix=|)| indent=| |
(5, 4) Name g prefix=|| suffix=|| indent=| |
(2, 8) MatchAs b prefix=|| suffix=|| indent=| |
(-1, -1) Load prefix=|| suffix=|| indent=||
(4, 8) MatchAs e prefix=|| suffix=|| indent=| |
(-1, -1) Load prefix=|| suffix=|| indent=||
5 changes: 5 additions & 0 deletions testdata/ast/match_as_or.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
match a:
case [b] as c:
d
case [e] | (f):
g

0 comments on commit 3fdf178

Please sign in to comment.