Nick Coghlan <ncogh...@gmail.com> added the comment:

You're right, I was confusing what happens automatically for classes defined in 
Python (i.e. the full treatment in type_new) vs those defined statically (i.e. 
just the parts in PyType_Ready).

Given that PyType_FromSpec doesn't currently support inheritance, providing a 
default tp_dealloc before the inherit_slots() call in PyType_Ready would work 
OK in the near term.

However, once inheritance support is added by #15146 then it would be wrong - 
the default slot entry would override an inherited one.

So, I think this adjustment actually needs to be handled in PyType_Ready, at 
some point after the inherit_slots() call.

Something like:

    /* Sanity check for tp_dealloc. */
    if ((type->tp_flags & Py_TPFLAGS_HEAPTYPE) &&
        (type->tp_dealloc == type_dealloc)) {
        /* Type has been declared as a heap type, but has inherited the
           default allocator. This can happen when using the limited API
           to dynamically create types.
         */
        type->tp_dealloc = subtype_dealloc;
    }

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue15142>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to