This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients Arfrever, alex, doko, jdemeyer, pitrou, python-dev, scoder, serhiy.storchaka, vstinner, xiang.zhang
Date 2021-04-20.18:37:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1618943835.98.0.953613853457.issue22079@roundup.psfhosted.org>
In-reply-to
Content
I recently reworked type_new() and PyType_New() in bpo-43770. I wrote documentation for the type_ready_inherit_as_structs() helper function of PyType_Ready():

// For static types, inherit tp_as_xxx structures from the base class
// if it's NULL.
//
// For heap types, tp_as_xxx structures are not NULL: they are set to the
// PyHeapTypeObject.as_xxx fields by type_new_alloc().
static void
type_ready_inherit_as_structs(PyTypeObject *type, PyTypeObject *base)

I hesitated to add assertions to ensure that fields are set if the type is a heap type.

One issue with static type is that it doesn't have the following fields of PyHeapTypeObject:

    PyAsyncMethods as_async;
    PyNumberMethods as_number;
    PyMappingMethods as_mapping;
    PySequenceMethods as_sequence; /* as_sequence comes after as_mapping,
                                      so that the mapping wins when both
                                      the mapping and the sequence define
                                      a given operator (e.g. __getitem__).
                                      see add_operators() in typeobject.c . */
    PyBufferProcs as_buffer;

Is there a reason to not add these fields to PyTypeObject? PyTypeObject is not part of the stable ABI.

Type inheritance without these fields make PyType_Ready() weird and more complex.
History
Date User Action Args
2021-04-20 18:37:16vstinnersetrecipients: + vstinner, doko, pitrou, scoder, Arfrever, alex, python-dev, serhiy.storchaka, jdemeyer, xiang.zhang
2021-04-20 18:37:15vstinnersetmessageid: <1618943835.98.0.953613853457.issue22079@roundup.psfhosted.org>
2021-04-20 18:37:15vstinnerlinkissue22079 messages
2021-04-20 18:37:15vstinnercreate