Hi Mark.

I've spoken with Guido, and we are willing to propose the following amendments 
to PEP 634:

- Require `__match_args__` to be a tuple.
- 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
    ...
```

Using this in C would look like:

```
PyTypeObject PyMySeq_Type = {
    ...
    .tp_flags = Py_TPFLAGS_MATCH_SEQ | ...,
    ...
}

PyTypeObject PyMyMap_Type = {
    ...
    .tp_flags = Py_TPFLAGS_MATCH_MAP | ...,
    ...
}
```

We believe that these changes will result in the best possible outcome:
- The new mechanism should faster than either PEP.
- The new mechanism should provide a better user experience than either PEP 
when defining types in either Python *or C*.

If these amendments were made, would you be comfortable withdrawing PEP 653? We 
think that if we're in agreement here, a compromise incorporating these 
promising changes into the current design would be preferable to submitting yet 
another large pattern matching PEP for a very busy SC to review and pronounce 
before the feature freeze. I am also willing, able, and eager to implement 
these changes promptly (perhaps even before the next alpha) if so.

Thanks for pushing us to make this better.

Brandt
_______________________________________________
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/QJR5TT5BW55PZFXJJFEYUCNZ5XQF256O/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to