Message391485
https://www.python.org/dev/peps/pep-0642/#representing-patterns-explicitly-in-the-abstract-syntax-tree covers the rationale for why it is potentially problematic to reuse expression nodes for match patterns: it doesn't semantically align with the fact that patterns are *not* expressions, so the AST ends up being closer to a concrete syntax tree than we would like.
For the specifics of the AST nodes:
* restricting sub expressions directly in the AST itself is tricky without side effects on the AST for non-pattern-matching code, so I'm intending to add any such restrictions that we want to enforce to the validator (other statements and expressions like yield, await, return, break, and continue already have separately enforced restrictions like that)
* cls needs to be an expression node to allow for attribute lookups
* the linked draft PR already updates the grammar to emit the new AST. MatchClass is able to collect the keyword args and their corresponding patterns in roughly the same way that MatchMapping collects its key:pattern pairs |
|
Date |
User |
Action |
Args |
2021-04-20 23:48:56 | ncoghlan | set | recipients:
+ ncoghlan, Mark.Shannon, Guido.van.Rossum, pablogsal, brandtbucher, BTaskaya, freundTech |
2021-04-20 23:48:56 | ncoghlan | set | messageid: <1618962536.54.0.193979873088.issue43892@roundup.psfhosted.org> |
2021-04-20 23:48:56 | ncoghlan | link | issue43892 messages |
2021-04-20 23:48:56 | ncoghlan | create | |
|