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.

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-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/2HDCJYULPKEDLHLMQH563VYZTG47ST3N/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to