On Wed, Jun 24, 2020 at 3:02 AM Chris Jerdonek <chris.jerdonek@gmail.com> wrote:
I have an exploratory question. In this section:

The alternatives may bind variables, as long as each alternative binds the same set of variables (excluding _). For example:
match something:
    ...
    case Foo(arg=x) | Bar(arg=x):  # Valid, both arms bind 'x'
        ...
    ...

Tweaking the above example slightly, would there be a way to modify the following so that, if the second alternative matched, then 'x' would have the value, say, None assigned to it?

match something:
    ...
    case Foo(arg=x) | Bar() (syntax assigning, say, None to x?)
        ...
    ...

That would let Bar be handled by the Foo case even if Bar doesn't take an argument. I'm not sure if this would ever be needed, but it's something I was wondering. I didn't see this covered but could have missed it.

That sounds like you are planning to put an 'if x is not None' check in the block. In most cases it would probably be cleaner to separate this out into two cases. (And yes, I can think of counterexamples, but they don't feel compelling enough to try and invent such syntax.)

--
--Guido van Rossum (python.org/~guido)