Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba21a49

Browse files
committed
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.
1 parent 82fc51c commit ba21a49

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

Objects/object.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,7 @@ PyCallable_Check(PyObject *x)
13731373
NoObject is usable as a non-NULL undefined value, used by the macro None.
13741374
There is (and should be!) no way to create other objects of this type,
13751375
so there is exactly one (which is indestructible, by the way).
1376+
(XXX This type and the type of NotImplemented below should be unified.)
13761377
*/
13771378

13781379
/* ARGSUSED */
@@ -1393,10 +1394,10 @@ none_dealloc(PyObject* ignore)
13931394
}
13941395

13951396

1396-
static PyTypeObject PyNothing_Type = {
1397+
static PyTypeObject PyNone_Type = {
13971398
PyObject_HEAD_INIT(&PyType_Type)
13981399
0,
1399-
"None",
1400+
"NoneType",
14001401
0,
14011402
0,
14021403
(destructor)none_dealloc, /*tp_dealloc*/ /*never called*/
@@ -1412,7 +1413,7 @@ static PyTypeObject PyNothing_Type = {
14121413
};
14131414

14141415
PyObject _Py_NoneStruct = {
1415-
PyObject_HEAD_INIT(&PyNothing_Type)
1416+
PyObject_HEAD_INIT(&PyNone_Type)
14161417
};
14171418

14181419
/* NotImplemented is an object that can be used to signal that an
@@ -1427,7 +1428,7 @@ NotImplemented_repr(PyObject *op)
14271428
static PyTypeObject PyNotImplemented_Type = {
14281429
PyObject_HEAD_INIT(&PyType_Type)
14291430
0,
1430-
"NotImplemented",
1431+
"NotImplementedType",
14311432
0,
14321433
0,
14331434
(destructor)none_dealloc, /*tp_dealloc*/ /*never called*/
@@ -1446,6 +1447,22 @@ PyObject _Py_NotImplementedStruct = {
14461447
PyObject_HEAD_INIT(&PyNotImplemented_Type)
14471448
};
14481449

1450+
void
1451+
_Py_ReadyTypes(void)
1452+
{
1453+
if (PyType_Ready(&PyType_Type) < 0)
1454+
Py_FatalError("Can't initialize 'type'");
1455+
1456+
if (PyType_Ready(&PyList_Type) < 0)
1457+
Py_FatalError("Can't initialize 'list'");
1458+
1459+
if (PyType_Ready(&PyNone_Type) < 0)
1460+
Py_FatalError("Can't initialize type(None)");
1461+
1462+
if (PyType_Ready(&PyNotImplemented_Type) < 0)
1463+
Py_FatalError("Can't initialize type(NotImplemented)");
1464+
}
1465+
14491466

14501467
#ifdef Py_TRACE_REFS
14511468

0 commit comments

Comments
 (0)