mcpyrate
mcpyrate copied to clipboard
Python 3.10: match/case
https://docs.python.org/3/whatsnew/3.10.html#pep-634-structural-pattern-matching
I almost missed the AST implications of this.
Check if we need to change something - sounds like at least the unparser will need some new cases.
https://docs.python.org/3/library/ast.html
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)
Additionally, but unrelatedly, the unparser doesn't support these yet (3.12+):
type_ignore = TypeIgnore(int lineno, string tag)
type_param = TypeVar(identifier name, expr? bound)
| ParamSpec(identifier name)
| TypeVarTuple(identifier name)
Even though mcpyrate already works on Pythons up to 3.12, it seems there's a bit of work for full proper support of 3.10+.
Also this (3.11+):
https://docs.python.org/3/library/ast.html#ast.TryStar
All these done as of b82af24.
That should be it for AST changes for 3.10, 3.11 and 3.12.