[issue42128] Structural Pattern Matching (PEP 634)

Batuhan Taskaya report at bugs.python.org
Fri Mar 12 16:30:32 EST 2021


Batuhan Taskaya <isidentical at gmail.com> added the comment:

> This seams really inconsistent with the rest of the ast, where identifiers are always wrapped in a ast.Name object. The only other exception to this is ast.Attribute.

import ... as <identifier>
from ... import ... as <identifier>
try:
   ...
except ... as <identifier>:
   ...

global <identifier>
nonlocal <identifier>
x(<identifier>=...)

All <identifier>s above are represented as strings. If <identifier> is guaranteed to be a single name, then it makes sense to just use an identifier instead of wrapping it with Name(). The reason that other stuff like "with ... as <expr>" uses <expr> instead of <identifier> is that you can use extended assignment targets (such as unpacking a tuple) over there. 

This rule applies to all other stuff, except for NamedExprs. Which I believe it is because the restriction might lift in the future, but now they are limited to only keep Name()s. 

I don't personally know why Brandt choosed to use identifier, though I'm a +1 on the current approach.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42128>
_______________________________________


More information about the Python-bugs-list mailing list