On Wed, Jun 24, 2020 at 11:47 AM M.-A. Lemburg <m...@egenix.com> 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.

-- 
--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-change-the-world/>
_______________________________________________
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/IRLLN4GZAHR62G2KHKGZ3Y5OEQPCL4AU/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to