Message391694
https://github.com/ncoghlan/cpython/pull/9/commits/54940a3817df3046da3f9c51d4d426a73b2ec786 implements Brandt's suggestion of disallowing NULL keys in MatchMapping and instead passing in an explicit "rest" identifier to capture the extra keys.
This did require moving to a multi-branch pattern definition in the grammar, similar to class patterns, in order to enforce the separating comma when both ordinary key:pattern pairs and a double-star target are present. I think it's a nice ergonomic improvement on the AST node itself though, as it makes it trivial to check if a mapping patterns captures extra keys or not (vs the relatively non-obvious check to see if the last key is NULL/None).
That just leaves updating the unparser to handle the new node types.
Capturing the latest node definitions from the draft PR:
pattern = MatchAlways
| 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? target)
-- The optional "rest" MatchMapping parameter handles capturing extra mapping keys
| MatchAs(pattern? pattern, identifier target)
| MatchOr(pattern* patterns)
attributes (int lineno, int col_offset, int end_lineno, int end_col_offset) |
|
Date |
User |
Action |
Args |
2021-04-23 13:16:29 | ncoghlan | set | recipients:
+ ncoghlan, Mark.Shannon, Guido.van.Rossum, pablogsal, brandtbucher, BTaskaya, freundTech |
2021-04-23 13:16:29 | ncoghlan | set | messageid: <1619183789.24.0.970499832124.issue43892@roundup.psfhosted.org> |
2021-04-23 13:16:29 | ncoghlan | link | issue43892 messages |
2021-04-23 13:16:28 | ncoghlan | create | |
|