How to support annotations for a custom type in a C extension?

Marco Sulla Marco.Sulla.Python at gmail.com
Sat Sep 18 02:40:08 EDT 2021


Ooook..... I have a question. Why is this code not present in
dictobject.c? Where are the dict annotations implemented?

On Sat, 18 Sept 2021 at 03:00, MRAB <python at mrabarnett.plus.com> wrote:
>
> On 2021-09-17 21:03, Marco Sulla wrote:
> > I created a custom dict in a C extension. Name it `promethea`. How can
> > I implement `promethea[str, str]`? Now I get:
> >
> > TypeError: 'type' object is not subscriptable
> >
> Somewhere you'll have a table of the class's methods. It needs an entry
> like this:
>
>
> 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.
> --
> https://mail.python.org/mailman/listinfo/python-list


More information about the Python-list mailing list