On Wed, Jun 24, 2020 at 7:27 AM M.-A. Lemburg <mal@egenix.com> wrote:
Wow, so 19 years after PEP 275, we are indeed getting a switch
statement. Nice :-)

Indeed. Fortunately there are now some better ideas to steal from other languages than C's switch. :-)

Something which struck me as odd when first scanning through the PEP
is the default case compared to other Python block statements:

match something:
    case 0 | 1 | 2:
        print("Small number")
    case [] | [_]:
        print("A short sequence")
    case str() | bytes():
        print("Something string-like")
    case _:
        print("Something else")

rather than what a Pythonista would probably expect:

match something:
    case 0 | 1 | 2:
        print("Small number")
    case [] | [_]:
        print("A short sequence")
    case str() | bytes():
        print("Something string-like")
    else:
        print("Something else")

Was there a reason for using a special value "_" as match-all value ?
I couldn't find any explanation for this in the PEP.

Nearly every other language whose pattern matching syntax we've examined uses _ as the wildcard.

The authors don't feel very strongly about whether to use `else:` or `case _:`. The latter would be possible even if we added an explicit `else` clause, and we like TOOWTDI. But it's clear that a lot of people *expect* to see `else`, and maybe seeing `case _:` is not the best introduction to wildcards for people who haven't seen a match statement before.

A wrinkle with `else` is that some of the authors would prefer to see it aligned with `match` rather than with the list of cases, but for others it feels like a degenerate case and should be aligned with those. (I'm in the latter camp.)

There still is a lively internal discussion going on, and we'll get back here when we have a shared opinion.
 
--
--Guido van Rossum (python.org/~guido)