I like this idea. I have few suggestions for the test cases you added, will
add them a bit later in the PR.

--
Ivan


On 15 December 2017 at 16:00, Serhiy Storchaka <storch...@gmail.com> wrote:

> The class itself always is passed as the first argument to
> __class_getitem__():
>
>     cls.__class_getitem__(cls, item)
>
> I propose to make __class_getitem__ a class method. This will make simpler
> implementing it in C. Currently it should be declared with flags
> METH_VARARGS|METH_STATIC and implementing as
>
> static PyObject *
> generic_class_getitem(PyObject *Py_UNUSED(self), PyObject *args)
> {
>     PyObject *type, *item;
>     if (!PyArg_UnpackTuple(args, "__class_getitem__", 2, 2, &type, &item))
> {
>         return NULL;
>     }
>     ...
> }
>
> Note an unused parameter and the need of manual unpacking arguments.
>
> If use it as a class method it should be declared with flags
> METH_O|METH_CLASS and implemented as
>
> static PyObject *
> generic_class_getitem(PyObject *type, PyObject *item)
> {
>     ...
> }
>
> See https://github.com/python/cpython/pull/4883 for sample.
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev@python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/levkivsky
> i%40gmail.com
>
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to