Commit c11e192d authored by Guido van Rossum's avatar Guido van Rossum

Thinking back to the 2.22 revision, I didn't like what I did there one

bit.  For one, this class:

    class C(object):
        def __new__(myclass, ...): ...

would have no way to call the __new__ method of its base class, and
the workaround (to create an intermediate base class whose __new__ you
can call) is ugly.

So, I've come up with a better solution that restores object.__new__,
but still solves the original problem, which is that built-in and
extension types shouldn't inherit object.__new__.  The solution is
simple: only "heap types" inherit tp_new.  Simpler, less code,
perfect!
parent a995c912
......@@ -447,7 +447,6 @@ solid_base(PyTypeObject *type)
staticforward void object_dealloc(PyObject *);
staticforward int object_init(PyObject *, PyObject *, PyObject *);
staticforward int add_tp_new_wrapper(PyTypeObject *);
static PyObject *
type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
......@@ -672,16 +671,6 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
/* Override slots that deserve it */
override_slots(type, type->tp_defined);
/* Special hack for __new__ */
if (type->tp_new == NULL) {
/* Can't do this earlier, or some nasty recursion happens. */
type->tp_new = PyType_GenericNew;
if (add_tp_new_wrapper(type) < 0) {
Py_DECREF(type);
return NULL;
}
}
return (PyObject *)type;
}
......@@ -913,7 +902,7 @@ PyTypeObject PyBaseObject_Type = {
0, /* tp_dictoffset */
object_init, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
0, /* tp_new */
PyType_GenericNew, /* tp_new */
object_free, /* tp_free */
};
......@@ -1163,7 +1152,9 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base)
COPYSLOT(tp_dictoffset);
COPYSLOT(tp_init);
COPYSLOT(tp_alloc);
COPYSLOT(tp_new);
if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
COPYSLOT(tp_new);
}
COPYSLOT(tp_free);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment