Skip to content

Commit 8182cc2

Browse files
authored
bpo-39573: Use the Py_TYPE() macro (pythonGH-21433)
Replace obj->ob_type with Py_TYPE(obj).
1 parent d878349 commit 8182cc2

File tree

7 files changed

+12
-12
lines changed

7 files changed

+12
-12
lines changed

Modules/_elementtree.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2040,7 +2040,7 @@ element_attrib_setter(ElementObject *self, PyObject *value, void *closure)
20402040
if (!PyDict_Check(value)) {
20412041
PyErr_Format(PyExc_TypeError,
20422042
"attrib must be dict, not %.200s",
2043-
value->ob_type->tp_name);
2043+
Py_TYPE(value)->tp_name);
20442044
return -1;
20452045
}
20462046
if (!self->extra) {

Objects/abstract.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ PyNumber_Long(PyObject *o)
13821382
if (!PyLong_Check(result)) {
13831383
PyErr_Format(PyExc_TypeError,
13841384
"__int__ returned non-int (type %.200s)",
1385-
result->ob_type->tp_name);
1385+
Py_TYPE(result)->tp_name);
13861386
Py_DECREF(result);
13871387
return NULL;
13881388
}
@@ -1391,7 +1391,7 @@ PyNumber_Long(PyObject *o)
13911391
"__int__ returned non-int (type %.200s). "
13921392
"The ability to return an instance of a strict subclass of int "
13931393
"is deprecated, and may be removed in a future version of Python.",
1394-
result->ob_type->tp_name)) {
1394+
Py_TYPE(result)->tp_name)) {
13951395
Py_DECREF(result);
13961396
return NULL;
13971397
}

Objects/genericaliasobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ga_dealloc(PyObject *self)
2020
Py_XDECREF(alias->origin);
2121
Py_XDECREF(alias->args);
2222
Py_XDECREF(alias->parameters);
23-
self->ob_type->tp_free(self);
23+
Py_TYPE(self)->tp_free(self);
2424
}
2525

2626
static int

Objects/unicodeobject.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -3325,7 +3325,7 @@ _PyUnicode_WideCharString_Converter(PyObject *obj, void *ptr)
33253325
}
33263326
PyErr_Format(PyExc_TypeError,
33273327
"argument must be str, not %.50s",
3328-
obj->ob_type->tp_name);
3328+
Py_TYPE(obj)->tp_name);
33293329
return 0;
33303330
}
33313331

@@ -3361,7 +3361,7 @@ _PyUnicode_WideCharString_Opt_Converter(PyObject *obj, void *ptr)
33613361
}
33623362
PyErr_Format(PyExc_TypeError,
33633363
"argument must be str or None, not %.50s",
3364-
obj->ob_type->tp_name);
3364+
Py_TYPE(obj)->tp_name);
33653365
return 0;
33663366
}
33673367

PC/_msi.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ static FNFCIGETNEXTCABINET(cb_getnextcabinet)
193193
if (!PyBytes_Check(result)) {
194194
PyErr_Format(PyExc_TypeError,
195195
"Incorrect return type %s from getnextcabinet",
196-
result->ob_type->tp_name);
196+
Py_TYPE(result)->tp_name);
197197
Py_DECREF(result);
198198
return FALSE;
199199
}
@@ -879,7 +879,7 @@ _msi_View_Execute(msiobj *self, PyObject *oparams)
879879
MSIHANDLE params = 0;
880880

881881
if (oparams != Py_None) {
882-
if (oparams->ob_type != &record_Type) {
882+
if (!Py_IS_TYPE(oparams, &record_Type)) {
883883
PyErr_SetString(PyExc_TypeError, "Execute argument must be a record");
884884
return NULL;
885885
}
@@ -955,7 +955,7 @@ _msi_View_Modify_impl(msiobj *self, int kind, PyObject *data)
955955
{
956956
int status;
957957

958-
if (data->ob_type != &record_Type) {
958+
if (!Py_IS_TYPE(data, &record_Type)) {
959959
PyErr_SetString(PyExc_TypeError, "Modify expects a record object");
960960
return NULL;
961961
}

PC/winreg.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ typedef struct {
112112
HKEY hkey;
113113
} PyHKEYObject;
114114

115-
#define PyHKEY_Check(op) ((op)->ob_type == &PyHKEY_Type)
115+
#define PyHKEY_Check(op) Py_IS_TYPE(op, &PyHKEY_Type)
116116

117117
static char *failMsg = "bad operand type";
118118

@@ -693,7 +693,7 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
693693
PyErr_Format(PyExc_TypeError,
694694
"Objects of type '%s' can not "
695695
"be used as binary registry values",
696-
value->ob_type->tp_name);
696+
Py_TYPE(value)->tp_name);
697697
return FALSE;
698698
}
699699

Tools/scripts/combinerefs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
3434
if the refcount changed.
3535
36-
typename is object->ob_type->tp_name, extracted from the second PYTHONDUMPREFS
36+
typename is Py_TYPE(object)->tp_name, extracted from the second PYTHONDUMPREFS
3737
output block.
3838
3939
repr is repr(object), extracted from the first PYTHONDUMPREFS output block.

0 commit comments

Comments
 (0)