Some background: the reason we decided not to do this is because cases are allowed to omit positional sub-patterns when matching. For example, it would be possible to write this:
``` >>> match n: ... case complex(42j): ... ... ... ``` Read that carefully! It would match any complex number with a *real* part equal to 42j. Which is to say, it would actually match *nothing*. I personally prefer the (admittedly wordier) status quo: ``` >>> match n: ... case complex(real=r, imag=i): ... ... ... ``` The problem with slice is much bigger, though: the expected attributes actually change depending on how many "args" there are, so a static mapping just isn't possible. Again, the status quo is much more explicit, for better or worse: ``` >>> match i: ... case slice(start=lo, stop=hi, step=by): ... pass ... ``` At one point, the original pattern matching proposal (and implementation) included support for a `__match_args_required__` attribute that could optionally be provided alongside `__match_args__`. With that, you could then set `complex.__match_args__ = ("real", "imag")` and `complex.__match_args_required__ = 2`, and get an error like: ``` >>> match n: ... case complex(42j): ... ... ... TypeError: complex() requires 2 positional sub-patterns (1 given) ``` Similarly, you could set `slice.__match_args__ = ("start", "stop", "step")` and `slice.__match_args_required__ = 2`, and get an error like: ``` >>> match i: ... case slice(stop): ... ... ... TypeError: slice() requires at least 2 positional sub-patterns (1 given) ``` We eventually dropped `__match_args_required__` to simplify the proposal, though. For anyone curious, all of our discussions during this period are archived in the issue tracker at: https://github.com/gvanrossum/patma/issues. Brandt _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/F4QHQ3ZHJNNVHD5QTPEJOV3UEM6ZPBQU/ Code of Conduct: http://python.org/psf/codeofconduct/