This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients BTaskaya, Guido.van.Rossum, Mark.Shannon, brandtbucher, freundTech, ncoghlan, pablogsal
Date 2021-04-23.13:16:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1619183789.24.0.970499832124.issue43892@roundup.psfhosted.org>
In-reply-to
Content
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)
History
Date User Action Args
2021-04-23 13:16:29ncoghlansetrecipients: + ncoghlan, Mark.Shannon, Guido.van.Rossum, pablogsal, brandtbucher, BTaskaya, freundTech
2021-04-23 13:16:29ncoghlansetmessageid: <1619183789.24.0.970499832124.issue43892@roundup.psfhosted.org>
2021-04-23 13:16:29ncoghlanlinkissue43892 messages
2021-04-23 13:16:28ncoghlancreate