How to support annotations for a custom type in a C extension?
Serhiy Storchaka
storchaka at gmail.com
Sat Sep 18 11:09:26 EDT 2021
18.09.21 03:54, MRAB пише:
> static PyMethodDef customdict_methods[] = {
> ...
> {"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_CLASS |
> METH_O | METH_COEXIST, PyDoc_STR("See PEP 585")},
> ...
> };
>
>
> Note the flags: METH_CLASS says that it's a class method and
> METH_COEXIST says that it should use this method instead of the slot.
"(PyCFunction)" is redundant, Py_GenericAlias already has the right
type. Overuse of casting to PyCFunction can hide actual bugs.
METH_COEXIST is not needed. There is no slot for __class_getitem__, and
even if it was, there would be no reasons to prohibit using it.
More information about the Python-list
mailing list