Add a function _Py_ReadyTypes() which initializes various and sundry

types -- currently Type, List, None and NotImplemented.  To be called
from Py_Initialize() instead of accumulating calls there.

Also rename type(None) to NoneType and type(NotImplemented) to
NotImplementedType -- naming the type identical to the object was
confusing.
This commit is contained in:
Guido van Rossum 2001-08-16 08:17:26 +00:00
parent 82fc51c19c
commit ba21a49f9d
1 changed files with 21 additions and 4 deletions

View File

@ -1373,6 +1373,7 @@ PyCallable_Check(PyObject *x)
NoObject is usable as a non-NULL undefined value, used by the macro None. NoObject is usable as a non-NULL undefined value, used by the macro None.
There is (and should be!) no way to create other objects of this type, There is (and should be!) no way to create other objects of this type,
so there is exactly one (which is indestructible, by the way). so there is exactly one (which is indestructible, by the way).
(XXX This type and the type of NotImplemented below should be unified.)
*/ */
/* ARGSUSED */ /* ARGSUSED */
@ -1393,10 +1394,10 @@ none_dealloc(PyObject* ignore)
} }
static PyTypeObject PyNothing_Type = { static PyTypeObject PyNone_Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(&PyType_Type)
0, 0,
"None", "NoneType",
0, 0,
0, 0,
(destructor)none_dealloc, /*tp_dealloc*/ /*never called*/ (destructor)none_dealloc, /*tp_dealloc*/ /*never called*/
@ -1412,7 +1413,7 @@ static PyTypeObject PyNothing_Type = {
}; };
PyObject _Py_NoneStruct = { PyObject _Py_NoneStruct = {
PyObject_HEAD_INIT(&PyNothing_Type) PyObject_HEAD_INIT(&PyNone_Type)
}; };
/* NotImplemented is an object that can be used to signal that an /* NotImplemented is an object that can be used to signal that an
@ -1427,7 +1428,7 @@ NotImplemented_repr(PyObject *op)
static PyTypeObject PyNotImplemented_Type = { static PyTypeObject PyNotImplemented_Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(&PyType_Type)
0, 0,
"NotImplemented", "NotImplementedType",
0, 0,
0, 0,
(destructor)none_dealloc, /*tp_dealloc*/ /*never called*/ (destructor)none_dealloc, /*tp_dealloc*/ /*never called*/
@ -1446,6 +1447,22 @@ PyObject _Py_NotImplementedStruct = {
PyObject_HEAD_INIT(&PyNotImplemented_Type) PyObject_HEAD_INIT(&PyNotImplemented_Type)
}; };
void
_Py_ReadyTypes(void)
{
if (PyType_Ready(&PyType_Type) < 0)
Py_FatalError("Can't initialize 'type'");
if (PyType_Ready(&PyList_Type) < 0)
Py_FatalError("Can't initialize 'list'");
if (PyType_Ready(&PyNone_Type) < 0)
Py_FatalError("Can't initialize type(None)");
if (PyType_Ready(&PyNotImplemented_Type) < 0)
Py_FatalError("Can't initialize type(NotImplemented)");
}
#ifdef Py_TRACE_REFS #ifdef Py_TRACE_REFS