![](https://secure.gravatar.com/avatar/3dc5fffe0e94dfa07067a45400213034.jpg?s=120&d=mm&r=g)
On 16/08/2020 8:23 pm, Jean Abou Samra wrote:
Hi there,
As a poor user, I am extremely excited about the possibilities PEP 622 (structural pattern matching) opens. I'd like to ask a few questions.
OOI, what possibilities? I'm genuinely interested know what problems PEP 622 would solve for you.
I hope these were not already answered in other threads, which it is hard to follow given the amounts of information.
First, I'd like to know wether walrus patterns are encouraged as an expressive way to explain the code in addition to comments, for example:
match number: case exact := numbers.Rational(): ... case inexact: ...
Here we rename number depending on the case clause that was taken. Would this be considered good practice? Maybe it'd be worth codifying in PEP 8 if PEP 622 is accepted?
A nit: how is the keywords module going to integrate soft keywords? Perhaps not at all?
Also, I see potential for a caveat:
match number: case int: # missing parentheses! ... case float: ... case Fraction: ...
In this case, if I understand the specification correctly, the first case will always match, right? Maybe the interpreter could throw a SyntaxWarning when a bare capture pattern (without a guard) is used as a pattern in any case clause other than the last one? As far as I understand, this could possibly prevent many of the mistakes in load/store that people have been rightfully complaining about so far. It's merely a stronger measure than letting static checkers do the work (since we don't all use these tools).
Finally, was as-based syntax considered as an alternative to walrus patterns, that is, PATTERN as NAME instead of NAME := PATTERN, as we have in the try statement? Given the extensive discussion, I guess it might have been rejected, so it could deserve a place under "Rejected ideas" -- this holds for all the above too, which I'm sorry about if it's dumb.
Best regards, Jean Abou Samra _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@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/2HDCJYUL... Code of Conduct: http://python.org/psf/codeofconduct/