astor
astor copied to clipboard
Added support for new ast nodes for pattern matching.
Pattern matching has been added to Python 3.10, which introduces four new ast
nodes. This adds support for those nodes.
This seems pretty straightforward, but tell me if I need to change anything else.
Be aware though Pattern matching AST is unstable right now: https://bugs.python.org/issue42128#msg388583
You'll want tests and a changelog entry. My PRs can serve as examples. But it does seem like this addition may be premature, anyway.
What I could gather from https://docs.python.org/3/library/ast.html#abstract-grammar
| Match(expr subject, match_case* cases)
...
match_case = (pattern pattern, expr? guard, stmt* body)
pattern = MatchValue(expr value)
| MatchSingleton(constant value)
| MatchSequence(pattern* patterns)
| MatchMapping(expr* keys, pattern* patterns, identifier? rest)
| MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)
| MatchStar(identifier? name)
-- The optional "rest" MatchMapping parameter handles capturing extra mapping keys
| MatchAs(pattern? pattern, identifier? name)
| MatchOr(pattern* patterns)
Of which MatchValue
, MatchSingleton
, MatchSequence
, MatchMapping
and MatchClass
seem to be missing