On Wed, Jun 24, 2020 at 11:47 AM M.-A. Lemburg firstname.lastname@example.org wrote:
Something I know the Perl camp is always very fond of is the matching on regexps. Is this possible using the proposal (sorry, I don't quite understand the __match__() protocol yet) ?
No, that's left for another day. Scala has string matching built into its pattern matching syntax, but for Python it would be an uphill battle to try to compete with regular expression syntax.
The problem I see with "case _" is that it's just too easy to miss when looking at the body of "match", even more so, since people will not necessarily put it at the end, or add it as or'ed add-on to some other case, e.g.
match something: case 0 | 1 | 2 | _: print("Small number or something else") case  | [_]: print("A short sequence") case _: print("Not sure what this is") case str() | bytes(): print("Something string-like")
That's just a bug in the user's code. We can't *stop* users from writing "case _:" -- note there are even more ways to spell it, e.g. "case x:" (where x is otherwise unused), or "case object():".
You could even declare the above stand-alone or or'ed use of "_" illegal and force use of "else" instead to push for TOOWTDI.
I guess we *could* syntactically disallow 0|_, but why bother? I don't expect anyone is going to write that and then expect the next case to be reachable. When it comes to catching unreachable code I think we have bigger fish to fry (e.g. f.close without the ()).
That said, we're on the fence on adding else.