I don't see how this extrapolates to arbitrary, extended match expressions? You're proposing a slightly more flexible switch, which match is only intended to be as the most basic case. Even if you purely swapped it out with any the various proposals for identifying a constant vs a target, it's still far more verbose than any of them.
On Sat, Jul 4, 2020 at 4:31 PM Shantanu Jain <hauntsani...@gmail.com> wrote: > Thank you for this PEP! Pattern matching is really exciting. > > As the PEP mentions and the thread evidences, the current dot syntax for > the “constant value pattern” is a tricky point. Given this, I thought I’d > throw another suggestion into the bikeshed. > > Use percent placeholder to indicate lookup (or even eval) semantics for a > given name. For example: > ``` > FOO = 1 > value = 0 > > match value: > case %(FOO): # This would not be matched > ... > case BAR: # This would be matched > ... > ``` > I like this syntax because it’s reminiscent of named substitution in > percent formatted strings. It suggests a substitution / placeholder > metaphor that is quite fitting. It has the benefit of not introducing a new > symbol into Python and being explicit and hard to miss, including in nested > contexts. > > Note, it seems like it would also be technically possible to use curly > braces (the more idiomatic means of named substitution in Python 3): > ``` > case {FOO}: … > ``` > The main downside of this is that it could look like some sort of > singleton “set pattern” (note that the PEP only supports “sequence > patterns” and “mapping patterns”). > (But set patterns maybe don’t quite make sense + if your set pattern had > multiple elements you’d still get a SyntaxError. For other examples where > something in Python looks like a set literal but isn’t, refer to `{}` and > f-strings, so it’s maybe not the biggest stretch) > > Both of these suggestions could also allow us more flexibility for > constant value patterns, since currently there isn't a good way to match > against a constant expression. For example, we could extend this syntax to > allow us to express: > ``` > case %(2 ** 10): ... > ``` > _______________________________________________ > 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/YQUCFREQ2P7NENOTPBE277I3BZ6DGXSR/ > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ 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/WTUD5LSX7QZVSJM4UZLAVLW5OV4PNWS2/ Code of Conduct: http://python.org/psf/codeofconduct/