diff --git a/pasta/base/annotate.py b/pasta/base/annotate.py index c87b8ce..7c8ad2c 100644 --- a/pasta/base/annotate.py +++ b/pasta/base/annotate.py @@ -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): diff --git a/testdata/ast/golden/3.11/match_as_or.out b/testdata/ast/golden/3.11/match_as_or.out new file mode 100644 index 0000000..2dfd4fc --- /dev/null +++ b/testdata/ast/golden/3.11/match_as_or.out @@ -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=|| diff --git a/testdata/ast/match_as_or.in b/testdata/ast/match_as_or.in new file mode 100644 index 0000000..4cf7656 --- /dev/null +++ b/testdata/ast/match_as_or.in @@ -0,0 +1,5 @@ +match a: + case [b] as c: + d + case [e] | (f): + g