On Wed, Mar 31, 2021 at 2:30 AM Mark Shannon <mark@hotpy.org> wrote:
> - Add new `__match_seq__` and `__match_map__` special attributes, corresponding to new public `Py_TPFLAGS_MATCH_SEQ` and `Py_TPFLAGS_MATCH_MAP` flags for use in `tp_flags`. When Python classes are defined with one or both of these attributes set to a boolean value, `type.__new__` will update the flags on the type to reflect the change (using a similar mechanism as `__slots__` definitions). They will be inherited otherwise. For convenience, `collections.abc.Sequence` will define `__match_seq__ = True`, and `collections.abc.Mapping` will define `__match_map__ = True`.
>
> Using this in Python would look like:
>
> ```
> class MySeq:
>      __match_seq__ = True
>      ...
>
> class MyMap:
>      __match_map__ = True
>      ...
> ```

I don't like the way this need special inheritance rules, where
inheriting one attribute mutates the value of another.
It seems convoluted.

Consider:

class WhatIsIt(MySeq, MyMap):
     pass

With __match_container__ it works as expected with no special
inheritance rules.

Wait a minute, do you expect WhatIsIt to be a sequence but not a map? *I* would expect that it is both, and that's exactly what Brandt's proposal does. So I see this as a plus.
 
I think we are close to agreement on the mechanism for selecting which
pattern to match, but I still want the better defined semantics of PEP 653.

I don't know that PEP 653's semantics are better. Have you analyzed any *differences* besides the proposal above? I've personally found reading your pseudo-code very difficult, so I simply don't know.
 
--
--Guido van Rossum (python.org/~guido)