[Python-ideas] Match statement brainstorm

Greg Ewing greg.ewing at canterbury.ac.nz
Tue May 24 02:08:11 EDT 2016


> On Mon, May 23, 2016 at 7:57 PM, Michael Selik <michael.selik at gmail.com> wrote:
> 
>>def demo(arg):
>>    if p, q ?= arg.x, arg.y:                        # dict structure
>>    elif x ?= arg.x and isinstance(x, int)          # assignment + guard
>>    elif a, b, *_ ?= arg:                           # tuple structure
>>    elif isinstance(arg, Mapping):                  # nothing new here

I'm unenthusiastic about this -- the above looks like
an unreadable mess to me.

Some other worries:

* It appears that this would have to work by means of
exception-catching in the rhs, so it's really a
disguised form of the except: expression proposal;
is that intentional?

* It could also be abused to get an assigment-in-
expression anywhere you wanted. Such things have
been rejected before; are we changing our mind
on that?

* THere would be no hope of checking for coverage
of all cases in a static checker.

I feel like we've wandered a long way from the idea
we started with, which is something to facilitate
a Haskell-like case-analysis style of programming,
and ended up with something much looser that tries
to be all things to everyone.

-- 
Greg


More information about the Python-ideas mailing list