Skip to content

Commit dffe4c0

Browse files
authored
bpo-39573: Finish converting to new Py_IS_TYPE() macro (GH-18601)
1 parent 22a9a54 commit dffe4c0

23 files changed

+56
-57
lines changed

Include/py_curses.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ typedef struct {
6464
char *encoding;
6565
} PyCursesWindowObject;
6666

67-
#define PyCursesWindow_Check(v) (Py_TYPE(v) == &PyCursesWindow_Type)
67+
#define PyCursesWindow_Check(v) Py_IS_TYPE(v, &PyCursesWindow_Type)
6868

6969
#define PyCurses_CAPSULE_NAME "_curses._C_API"
7070

@@ -97,4 +97,3 @@ static const char catchall_NULL[] = "curses function returned NULL";
9797

9898
#endif /* !defined(Py_CURSES_H) */
9999

100-

Modules/_asynciomodule.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ future_set_exception(FutureObj *fut, PyObject *exc)
572572
PyErr_SetString(PyExc_TypeError, "invalid exception object");
573573
return NULL;
574574
}
575-
if ((PyObject*)Py_TYPE(exc_val) == PyExc_StopIteration) {
575+
if (Py_IS_TYPE(exc_val, (PyTypeObject *)PyExc_StopIteration)) {
576576
Py_DECREF(exc_val);
577577
PyErr_SetString(PyExc_TypeError,
578578
"StopIteration interacts badly with generators "

Modules/_collectionsmodule.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ deque_copy(PyObject *deque, PyObject *Py_UNUSED(ignored))
489489
{
490490
PyObject *result;
491491
dequeobject *old_deque = (dequeobject *)deque;
492-
if (Py_TYPE(deque) == &deque_type) {
492+
if (Py_IS_TYPE(deque, &deque_type)) {
493493
dequeobject *new_deque;
494494
PyObject *rv;
495495

Modules/_elementtree.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2366,7 +2366,7 @@ typedef struct {
23662366
char insert_pis;
23672367
} TreeBuilderObject;
23682368

2369-
#define TreeBuilder_CheckExact(op) (Py_TYPE(op) == &TreeBuilder_Type)
2369+
#define TreeBuilder_CheckExact(op) Py_IS_TYPE((op), &TreeBuilder_Type)
23702370

23712371
/* -------------------------------------------------------------------- */
23722372
/* constructor and destructor */

Modules/_io/bufferedio.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -1449,8 +1449,8 @@ _io_BufferedReader___init___impl(buffered *self, PyObject *raw,
14491449
return -1;
14501450
_bufferedreader_reset_buf(self);
14511451

1452-
self->fast_closed_checks = (Py_TYPE(self) == &PyBufferedReader_Type &&
1453-
Py_TYPE(raw) == &PyFileIO_Type);
1452+
self->fast_closed_checks = (Py_IS_TYPE(self, &PyBufferedReader_Type) &&
1453+
Py_IS_TYPE(raw, &PyFileIO_Type));
14541454

14551455
self->ok = 1;
14561456
return 0;
@@ -1795,8 +1795,8 @@ _io_BufferedWriter___init___impl(buffered *self, PyObject *raw,
17951795
_bufferedwriter_reset_buf(self);
17961796
self->pos = 0;
17971797

1798-
self->fast_closed_checks = (Py_TYPE(self) == &PyBufferedWriter_Type &&
1799-
Py_TYPE(raw) == &PyFileIO_Type);
1798+
self->fast_closed_checks = (Py_IS_TYPE(self, &PyBufferedWriter_Type) &&
1799+
Py_IS_TYPE(raw, &PyFileIO_Type));
18001800

18011801
self->ok = 1;
18021802
return 0;
@@ -2309,8 +2309,8 @@ _io_BufferedRandom___init___impl(buffered *self, PyObject *raw,
23092309
_bufferedwriter_reset_buf(self);
23102310
self->pos = 0;
23112311

2312-
self->fast_closed_checks = (Py_TYPE(self) == &PyBufferedRandom_Type &&
2313-
Py_TYPE(raw) == &PyFileIO_Type);
2312+
self->fast_closed_checks = (Py_IS_TYPE(self, &PyBufferedRandom_Type) &&
2313+
Py_IS_TYPE(raw, &PyFileIO_Type));
23142314

23152315
self->ok = 1;
23162316
return 0;

Modules/_io/stringio.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ stringio_iternext(stringio *self)
402402
CHECK_CLOSED(self);
403403
ENSURE_REALIZED(self);
404404

405-
if (Py_TYPE(self) == &PyStringIO_Type) {
405+
if (Py_IS_TYPE(self, &PyStringIO_Type)) {
406406
/* Skip method call overhead for speed */
407407
line = _stringio_readline(self, -1);
408408
}

Modules/_io/textio.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ _textiowrapper_decode(PyObject *decoder, PyObject *bytes, int eof)
897897
{
898898
PyObject *chars;
899899

900-
if (Py_TYPE(decoder) == &PyIncrementalNewlineDecoder_Type)
900+
if (Py_IS_TYPE(decoder, &PyIncrementalNewlineDecoder_Type))
901901
chars = _PyIncrementalNewlineDecoder_decode(decoder, bytes, eof);
902902
else
903903
chars = PyObject_CallMethodObjArgs(decoder, _PyIO_str_decode, bytes,
@@ -1226,15 +1226,15 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
12261226
/* Finished sorting out the codec details */
12271227
Py_CLEAR(codec_info);
12281228

1229-
if (Py_TYPE(buffer) == &PyBufferedReader_Type ||
1230-
Py_TYPE(buffer) == &PyBufferedWriter_Type ||
1231-
Py_TYPE(buffer) == &PyBufferedRandom_Type)
1229+
if (Py_IS_TYPE(buffer, &PyBufferedReader_Type) ||
1230+
Py_IS_TYPE(buffer, &PyBufferedWriter_Type) ||
1231+
Py_IS_TYPE(buffer, &PyBufferedRandom_Type))
12321232
{
12331233
if (_PyObject_LookupAttrId(buffer, &PyId_raw, &raw) < 0)
12341234
goto error;
12351235
/* Cache the raw FileIO object to speed up 'closed' checks */
12361236
if (raw != NULL) {
1237-
if (Py_TYPE(raw) == &PyFileIO_Type)
1237+
if (Py_IS_TYPE(raw, &PyFileIO_Type))
12381238
self->raw = raw;
12391239
else
12401240
Py_DECREF(raw);
@@ -1466,7 +1466,7 @@ textiowrapper_closed_get(textio *self, void *context);
14661466
do { \
14671467
int r; \
14681468
PyObject *_res; \
1469-
if (Py_TYPE(self) == &PyTextIOWrapper_Type) { \
1469+
if (Py_IS_TYPE(self, &PyTextIOWrapper_Type)) { \
14701470
if (self->raw != NULL) \
14711471
r = _PyFileIO_closed(self->raw); \
14721472
else { \
@@ -1937,7 +1937,7 @@ _io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n)
19371937
if (bytes == NULL)
19381938
goto fail;
19391939

1940-
if (Py_TYPE(self->decoder) == &PyIncrementalNewlineDecoder_Type)
1940+
if (Py_IS_TYPE(self->decoder, &PyIncrementalNewlineDecoder_Type))
19411941
decoded = _PyIncrementalNewlineDecoder_decode(self->decoder,
19421942
bytes, 1);
19431943
else
@@ -3079,7 +3079,7 @@ textiowrapper_iternext(textio *self)
30793079
CHECK_ATTACHED(self);
30803080

30813081
self->telling = 0;
3082-
if (Py_TYPE(self) == &PyTextIOWrapper_Type) {
3082+
if (Py_IS_TYPE(self, &PyTextIOWrapper_Type)) {
30833083
/* Skip method call overhead for speed */
30843084
line = _textiowrapper_readline(self, -1);
30853085
}

Modules/_pickle.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -4974,7 +4974,7 @@ Pickler_set_memo(PicklerObject *self, PyObject *obj, void *Py_UNUSED(ignored))
49744974
return -1;
49754975
}
49764976

4977-
if (Py_TYPE(obj) == &PicklerMemoProxyType) {
4977+
if (Py_IS_TYPE(obj, &PicklerMemoProxyType)) {
49784978
PicklerObject *pickler =
49794979
((PicklerMemoProxyObject *)obj)->pickler;
49804980

@@ -7519,7 +7519,7 @@ Unpickler_set_memo(UnpicklerObject *self, PyObject *obj, void *Py_UNUSED(ignored
75197519
return -1;
75207520
}
75217521

7522-
if (Py_TYPE(obj) == &UnpicklerMemoProxyType) {
7522+
if (Py_IS_TYPE(obj, &UnpicklerMemoProxyType)) {
75237523
UnpicklerObject *unpickler =
75247524
((UnpicklerMemoProxyObject *)obj)->unpickler;
75257525

Modules/_threadmodule.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ _ldict(localobject *self)
844844
}
845845
}
846846
else {
847-
assert(Py_TYPE(dummy) == &localdummytype);
847+
assert(Py_IS_TYPE(dummy, &localdummytype));
848848
ldict = ((localdummyobject *) dummy)->localdict;
849849
}
850850

@@ -1209,7 +1209,7 @@ release_sentinel(void *wr_raw)
12091209
PyObject *obj = PyWeakref_GET_OBJECT(wr);
12101210
lockobject *lock;
12111211
if (obj != Py_None) {
1212-
assert(Py_TYPE(obj) == &Locktype);
1212+
assert(Py_IS_TYPE(obj, &Locktype));
12131213
lock = (lockobject *) obj;
12141214
if (lock->locked) {
12151215
PyThread_release_lock(lock->lock_lock);

Modules/cjkcodecs/multibytecodec.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ typedef struct {
6565
MultibyteCodec *codec;
6666
} MultibyteCodecObject;
6767

68-
#define MultibyteCodec_Check(op) (Py_TYPE(op) == &MultibyteCodec_Type)
68+
#define MultibyteCodec_Check(op) Py_IS_TYPE((op), &MultibyteCodec_Type)
6969

7070
#define _MultibyteStatefulCodec_HEAD \
7171
PyObject_HEAD \

Modules/itertoolsmodule.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ teedataobject_traverse(teedataobject *tdo, visitproc visit, void * arg)
527527
static void
528528
teedataobject_safe_decref(PyObject *obj)
529529
{
530-
while (obj && Py_TYPE(obj) == &teedataobject_type &&
530+
while (obj && Py_IS_TYPE(obj, &teedataobject_type) &&
531531
Py_REFCNT(obj) == 1) {
532532
PyObject *nextlink = ((teedataobject *)obj)->nextlink;
533533
((teedataobject *)obj)->nextlink = NULL;

Objects/abstract.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2472,7 +2472,7 @@ object_recursive_isinstance(PyThreadState *tstate, PyObject *inst, PyObject *cls
24722472
_Py_IDENTIFIER(__instancecheck__);
24732473

24742474
/* Quick test for an exact match */
2475-
if (Py_TYPE(inst) == (PyTypeObject *)cls) {
2475+
if (Py_IS_TYPE(inst, (PyTypeObject *)cls)) {
24762476
return 1;
24772477
}
24782478

Objects/descrobject.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ typedef struct {
11781178
PyObject *self;
11791179
} wrapperobject;
11801180

1181-
#define Wrapper_Check(v) (Py_TYPE(v) == &_PyMethodWrapper_Type)
1181+
#define Wrapper_Check(v) Py_IS_TYPE(v, &_PyMethodWrapper_Type)
11821182

11831183
static void
11841184
wrapper_dealloc(wrapperobject *wp)
@@ -1628,7 +1628,7 @@ property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset,
16281628
if (rc <= 0) {
16291629
return rc;
16301630
}
1631-
if (Py_TYPE(self) == &PyProperty_Type) {
1631+
if (Py_IS_TYPE(self, &PyProperty_Type)) {
16321632
Py_XSETREF(self->prop_doc, get_doc);
16331633
}
16341634
else {

Objects/exceptions.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ oserror_init(PyOSErrorObject *self, PyObject **p_args,
875875

876876
/* self->filename will remain Py_None otherwise */
877877
if (filename && filename != Py_None) {
878-
if (Py_TYPE(self) == (PyTypeObject *) PyExc_BlockingIOError &&
878+
if (Py_IS_TYPE(self, (PyTypeObject *) PyExc_BlockingIOError) &&
879879
PyNumber_Check(filename)) {
880880
/* BlockingIOError's 3rd argument can be the number of
881881
* characters written.
@@ -1379,7 +1379,7 @@ SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds)
13791379
* Only applies to SyntaxError instances, not to subclasses such
13801380
* as TabError or IndentationError (see issue #31161)
13811381
*/
1382-
if ((PyObject*)Py_TYPE(self) == PyExc_SyntaxError &&
1382+
if (Py_IS_TYPE(self, (PyTypeObject *)PyExc_SyntaxError) &&
13831383
self->text && PyUnicode_Check(self->text) &&
13841384
_report_missing_parentheses(self) < 0) {
13851385
return -1;

Objects/genobject.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1216,10 +1216,10 @@ static PyAsyncGenASend *ag_asend_freelist[_PyAsyncGen_MAXFREELIST];
12161216
static int ag_asend_freelist_free = 0;
12171217

12181218
#define _PyAsyncGenWrappedValue_CheckExact(o) \
1219-
(Py_TYPE(o) == &_PyAsyncGenWrappedValue_Type)
1219+
Py_IS_TYPE(o, &_PyAsyncGenWrappedValue_Type)
12201220

12211221
#define PyAsyncGenASend_CheckExact(o) \
1222-
(Py_TYPE(o) == &_PyAsyncGenASend_Type)
1222+
Py_IS_TYPE(o, &_PyAsyncGenASend_Type)
12231223

12241224

12251225
static int
@@ -1442,7 +1442,7 @@ PyAsyncGen_ClearFreeLists(void)
14421442
while (ag_asend_freelist_free) {
14431443
PyAsyncGenASend *o;
14441444
o = ag_asend_freelist[--ag_asend_freelist_free];
1445-
assert(Py_TYPE(o) == &_PyAsyncGenASend_Type);
1445+
assert(Py_IS_TYPE(o, &_PyAsyncGenASend_Type));
14461446
PyObject_GC_Del(o);
14471447
}
14481448

Objects/listobject.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -2052,8 +2052,8 @@ unsafe_latin_compare(PyObject *v, PyObject *w, MergeState *ms)
20522052
int res;
20532053

20542054
/* Modified from Objects/unicodeobject.c:unicode_compare, assuming: */
2055-
assert(Py_TYPE(v) == Py_TYPE(w));
2056-
assert(Py_TYPE(v) == &PyUnicode_Type);
2055+
assert(Py_IS_TYPE(v, &PyUnicode_Type));
2056+
assert(Py_IS_TYPE(w, &PyUnicode_Type));
20572057
assert(PyUnicode_KIND(v) == PyUnicode_KIND(w));
20582058
assert(PyUnicode_KIND(v) == PyUnicode_1BYTE_KIND);
20592059

@@ -2075,8 +2075,8 @@ unsafe_long_compare(PyObject *v, PyObject *w, MergeState *ms)
20752075
PyLongObject *vl, *wl; sdigit v0, w0; int res;
20762076

20772077
/* Modified from Objects/longobject.c:long_compare, assuming: */
2078-
assert(Py_TYPE(v) == Py_TYPE(w));
2079-
assert(Py_TYPE(v) == &PyLong_Type);
2078+
assert(Py_IS_TYPE(v, &PyLong_Type));
2079+
assert(Py_IS_TYPE(w, &PyLong_Type));
20802080
assert(Py_ABS(Py_SIZE(v)) <= 1);
20812081
assert(Py_ABS(Py_SIZE(w)) <= 1);
20822082

@@ -2103,8 +2103,8 @@ unsafe_float_compare(PyObject *v, PyObject *w, MergeState *ms)
21032103
int res;
21042104

21052105
/* Modified from Objects/floatobject.c:float_richcompare, assuming: */
2106-
assert(Py_TYPE(v) == Py_TYPE(w));
2107-
assert(Py_TYPE(v) == &PyFloat_Type);
2106+
assert(Py_IS_TYPE(v, &PyFloat_Type));
2107+
assert(Py_IS_TYPE(w, &PyFloat_Type));
21082108

21092109
res = PyFloat_AS_DOUBLE(v) < PyFloat_AS_DOUBLE(w);
21102110
assert(res == PyObject_RichCompareBool(v, w, Py_LT));
@@ -2125,8 +2125,8 @@ unsafe_tuple_compare(PyObject *v, PyObject *w, MergeState *ms)
21252125
int k;
21262126

21272127
/* Modified from Objects/tupleobject.c:tuplerichcompare, assuming: */
2128-
assert(Py_TYPE(v) == Py_TYPE(w));
2129-
assert(Py_TYPE(v) == &PyTuple_Type);
2128+
assert(Py_IS_TYPE(v, &PyTuple_Type));
2129+
assert(Py_IS_TYPE(w, &PyTuple_Type));
21302130
assert(Py_SIZE(v) > 0);
21312131
assert(Py_SIZE(w) > 0);
21322132

@@ -2247,7 +2247,7 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse)
22472247
* set ms appropriately. */
22482248
if (saved_ob_size > 1) {
22492249
/* Assume the first element is representative of the whole list. */
2250-
int keys_are_in_tuples = (Py_TYPE(lo.keys[0]) == &PyTuple_Type &&
2250+
int keys_are_in_tuples = (Py_IS_TYPE(lo.keys[0], &PyTuple_Type) &&
22512251
Py_SIZE(lo.keys[0]) > 0);
22522252

22532253
PyTypeObject* key_type = (keys_are_in_tuples ?
@@ -2262,7 +2262,7 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse)
22622262
for (i=0; i < saved_ob_size; i++) {
22632263

22642264
if (keys_are_in_tuples &&
2265-
!(Py_TYPE(lo.keys[i]) == &PyTuple_Type && Py_SIZE(lo.keys[i]) != 0)) {
2265+
!(Py_IS_TYPE(lo.keys[i], &PyTuple_Type) && Py_SIZE(lo.keys[i]) != 0)) {
22662266
keys_are_in_tuples = 0;
22672267
keys_are_all_same_type = 0;
22682268
break;
@@ -2275,7 +2275,7 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse)
22752275
PyTuple_GET_ITEM(lo.keys[i], 0) :
22762276
lo.keys[i]);
22772277

2278-
if (Py_TYPE(key) != key_type) {
2278+
if (!Py_IS_TYPE(key, key_type)) {
22792279
keys_are_all_same_type = 0;
22802280
/* If keys are in tuple we must loop over the whole list to make
22812281
sure all items are tuples */

Objects/namespaceobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ namespace_repr(PyObject *ns)
7272
PyObject *separator, *pairsrepr, *repr = NULL;
7373
const char * name;
7474

75-
name = (Py_TYPE(ns) == &_PyNamespace_Type) ? "namespace"
75+
name = Py_IS_TYPE(ns, &_PyNamespace_Type) ? "namespace"
7676
: Py_TYPE(ns)->tp_name;
7777

7878
i = Py_ReprEnter(ns);

Objects/tupleobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ tupledealloc(PyTupleObject *op)
237237
#if PyTuple_MAXSAVESIZE > 0
238238
if (len < PyTuple_MAXSAVESIZE &&
239239
numfree[len] < PyTuple_MAXFREELIST &&
240-
Py_TYPE(op) == &PyTuple_Type)
240+
Py_IS_TYPE(op, &PyTuple_Type))
241241
{
242242
op->ob_item[0] = (PyObject *) free_list[len];
243243
numfree[len]++;

Objects/typeobject.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -5335,7 +5335,7 @@ PyType_Ready(PyTypeObject *type)
53355335
NULL when type is &PyBaseObject_Type, and we know its ob_type is
53365336
not NULL (it's initialized to &PyType_Type). But coverity doesn't
53375337
know that. */
5338-
if (Py_TYPE(type) == NULL && base != NULL) {
5338+
if (Py_IS_TYPE(type, NULL) && base != NULL) {
53395339
Py_SET_TYPE(type, Py_TYPE(base));
53405340
}
53415341

@@ -6645,7 +6645,7 @@ slot_tp_getattr_hook(PyObject *self, PyObject *name)
66456645
needed, with call_attribute. */
66466646
getattribute = _PyType_LookupId(tp, &PyId___getattribute__);
66476647
if (getattribute == NULL ||
6648-
(Py_TYPE(getattribute) == &PyWrapperDescr_Type &&
6648+
(Py_IS_TYPE(getattribute, &PyWrapperDescr_Type) &&
66496649
((PyWrapperDescrObject *)getattribute)->d_wrapped ==
66506650
(void *)PyObject_GenericGetAttr))
66516651
res = PyObject_GenericGetAttr(self, name);
@@ -7352,7 +7352,7 @@ update_one_slot(PyTypeObject *type, slotdef *p)
73527352
}
73537353
continue;
73547354
}
7355-
if (Py_TYPE(descr) == &PyWrapperDescr_Type &&
7355+
if (Py_IS_TYPE(descr, &PyWrapperDescr_Type) &&
73567356
((PyWrapperDescrObject *)descr)->d_base->name_strobj == p->name_strobj) {
73577357
void **tptr = resolve_slotdups(type, p->name_strobj);
73587358
if (tptr == NULL || tptr == ptr)
@@ -7375,7 +7375,7 @@ update_one_slot(PyTypeObject *type, slotdef *p)
73757375
use_generic = 1;
73767376
}
73777377
}
7378-
else if (Py_TYPE(descr) == &PyCFunction_Type &&
7378+
else if (Py_IS_TYPE(descr, &PyCFunction_Type) &&
73797379
PyCFunction_GET_FUNCTION(descr) ==
73807380
(PyCFunction)(void(*)(void))tp_new_wrapper &&
73817381
ptr == (void**)&type->tp_new)

0 commit comments

Comments
 (0)