On Mon, Aug 17, 2020 at 3:37 AM Mark Shannon wrote:
On 16/08/2020 9:41 pm, Guido van Rossum wrote:
On Sun, Aug 16, 2020 at 12:37 PM Jean Abou Samra
mailto:jean@abou-samra.fr> wrote: 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).
The reference implementation in fact does issue a SyntaxWarning for this case.
Shouldn't that detail be in the PEP?
Good point. I have added a note about this in the section on static checkers, under "Note about constants": https://github.com/python/peps/commit/6a7d6b831f9af7db651269231c77037aff6bad... (I should mention that the PEP authors are also grateful for your observation about what users expect for `case True`, and we are now discussing this in our issue tracker at https://github.com/gvanrossum/patma/issues/139. We're also discussing Jean's point about `as` vs. `:=` in issue 140.) -- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...