How to support annotations for a custom type in a C extension?
MRAB
python at mrabarnett.plus.com
Sat Sep 18 22:59:31 EDT 2021
On 2021-09-18 16:09, Serhiy Storchaka wrote:
> 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.
>
I borrowed that from listobject.c, which does have the cast.
> 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