STINNER Victor <[email protected]> added the comment:
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.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue22079>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com