Message391464
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. |
|
Date |
User |
Action |
Args |
2021-04-20 18:37:16 | vstinner | set | recipients:
+ vstinner, doko, pitrou, scoder, Arfrever, alex, python-dev, serhiy.storchaka, jdemeyer, xiang.zhang |
2021-04-20 18:37:15 | vstinner | set | messageid: <1618943835.98.0.953613853457.issue22079@roundup.psfhosted.org> |
2021-04-20 18:37:15 | vstinner | link | issue22079 messages |
2021-04-20 18:37:15 | vstinner | create | |
|