On Wed, Mar 31, 2021 at 2:30 AM Mark Shannon <m...@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)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/HZRGTO3UXRGXWXWXSX2H3WX6Y3Z37XOS/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to