As a tangential follow-up to my thought that _"the `:=` walrus operator seems 
to be usable as a substitute for new syntax"_, you can actually build a 
seemingly complete (if somewhat error-prone) _run-time_ pattern matching API 
using it:

https://gist.github.com/eric-wieser/da679ff9b1b1e99aa660d54cb0dbd517

Taking the `group_shapes` example from the PEP, the gist lets you write
```python
g = group_shapes()
if g in M(([], [point := M[Point](x := M._, y := M._), *(other := M._)])):
    print(f"Got {point.value} in the second group")
    process_coordinates(x.value, y.value)
elif g in M(...):
    # etc
```
This isn't an argument against adding new syntax, but I figured those 
discussing the PEP might be interested in what can already be done with today's 
syntax.

Eric
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/DNVHVJ5RHZYUKMXTGWLE2ZVNA4WPOUWE/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to