Feature or enhancement
The PyTypeObject fields tp_as_number, tp_as_sequence and tp_as_mapping can be set to NULL
which means that any code that wants to access a field in those structs needs to first check for NULL.
e.g. checking if an object is a sequence:
if (Py_TYPE(s)->tp_as_mapping && Py_TYPE(s)->tp_as_mapping->mp_length) {
this is ugly, a bit error prone and slower than necessary.
Instead, during PyType_Ready, any of these fields that are NULL should be made to pointer to a struct full of NULLs.
This would remove the need for the extra check:
if (Py_TYPE(s)->tp_as_mapping->mp_length) {
since we would be guaranteed that Py_TYPE(s)->tp_as_mapping is never NULL.
Immutable types can all share common constant structs, so this should use very little extra memory.
Feature or enhancement
The
PyTypeObjectfieldstp_as_number,tp_as_sequenceandtp_as_mappingcan be set toNULLwhich means that any code that wants to access a field in those structs needs to first check for
NULL.e.g. checking if an object is a sequence:
if (Py_TYPE(s)->tp_as_mapping && Py_TYPE(s)->tp_as_mapping->mp_length) {this is ugly, a bit error prone and slower than necessary.
Instead, during
PyType_Ready, any of these fields that areNULLshould be made to pointer to astructfull ofNULLs.This would remove the need for the extra check:
if (Py_TYPE(s)->tp_as_mapping->mp_length) {since we would be guaranteed that
Py_TYPE(s)->tp_as_mappingis never NULL.Immutable types can all share common constant structs, so this should use very little extra memory.