On Wed, Jun 24, 2020 at 11:47 AM M.-A. Lemburg <email@example.com
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.
case 0 | 1 | 2 | _:
print("Small number or something else")
case  | [_]:
print("A short sequence")
print("Not sure what this is")
case str() | bytes():
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
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.