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

Reply via email to