Nick Coghlan <ncogh...@gmail.com> added the comment:

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

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue43892>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to