[issue43916] Check that new heap types cannot be created uninitialised

Serhiy Storchaka report at bugs.python.org
Mon Apr 26 07:48:11 EDT 2021


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

>From Objects/typeobject.c:

        /* The condition below could use some explanation.
           It appears that tp_new is not inherited for static types
           whose base class is 'object'; this seems to be a precaution
           so that old extension types don't suddenly become
           callable (object.__new__ wouldn't insure the invariants
           that the extension type's own factory function ensures).
           Heap types, of course, are under our control, so they do
           inherit tp_new; static extension types that specify some
           other built-in type as the default also
           inherit object.__new__. */
        if (base != &PyBaseObject_Type ||
            (type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
            if (type->tp_new == NULL)
                type->tp_new = base->tp_new;
        }

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43916>
_______________________________________


More information about the Python-bugs-list mailing list