[Python-Dev] Make class_getitem a class method (original) (raw)

Ivan Levkivskyi levkivskyi at gmail.com
Fri Dec 15 10:25:17 EST 2017


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 <storchaka at gmail.com> wrote:

The class itself always is passed as the first argument to classgetitem():

cls.classgetitem(cls, item) I propose to make classgetitem a class method. This will make simpler implementing it in C. Currently it should be declared with flags METHVARARGS|METHSTATIC and implementing as static PyObject * genericclassgetitem(PyObject *PyUNUSED(self), PyObject *args) { PyObject *type, *item; if (!PyArgUnpackTuple(args, "classgetitem", 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 METHO|METHCLASS and implemented as static PyObject * genericclassgetitem(PyObject *type, PyObject *item) { ... } See https://github.com/python/cpython/pull/4883 for sample.


Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/levkivsky i%40gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20171215/a5a184fd/attachment.html>



More information about the Python-Dev mailing list