bpo-39573: Use Py_IS_TYPE() macro to check for types (GH-18809) · python/cpython@5572870 (original) (raw)

10 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -573,7 +573,7 @@ keyobject_richcompare(PyObject *ko, PyObject *other, int op)
573 573 PyObject *answer;
574 574 PyObject* stack[2];
575 575
576 -if (Py_TYPE(other) != &keyobject_type){
576 +if (!Py_IS_TYPE(other, &keyobject_type)) {
577 577 PyErr_Format(PyExc_TypeError, "other argument must be K instance");
578 578 return NULL;
579 579 }
Original file line number Diff line number Diff line change
@@ -938,7 +938,7 @@ local_getattro(localobject *self, PyObject *name)
938 938 if (r == -1)
939 939 return NULL;
940 940
941 -if (Py_TYPE(self) != &localtype)
941 +if (!Py_IS_TYPE(self, &localtype))
942 942 /* use generic lookup for subtypes */
943 943 return _PyObject_GenericGetAttrWithDict(
944 944 (PyObject *)self, name, ldict, 0);
@@ -1400,7 +1400,7 @@ static PyStructSequence_Desc ExceptHookArgs_desc = {
1400 1400 static PyObject *
1401 1401 thread_excepthook(PyObject *self, PyObject *args)
1402 1402 {
1403 -if (Py_TYPE(args) != &ExceptHookArgsType) {
1403 +if (!Py_IS_TYPE(args, &ExceptHookArgsType)) {
1404 1404 PyErr_SetString(PyExc_TypeError,
1405 1405 "_thread.excepthook argument type "
1406 1406 "must be ExceptHookArgs");
Original file line number Diff line number Diff line change
@@ -614,7 +614,7 @@ itertools_teedataobject_impl(PyTypeObject *type, PyObject *it,
614 614
615 615 if (len == LINKCELLS) {
616 616 if (next != Py_None) {
617 -if (Py_TYPE(next) != &teedataobject_type)
617 +if (!Py_IS_TYPE(next, &teedataobject_type))
618 618 goto err;
619 619 assert(tdo->nextlink == NULL);
620 620 Py_INCREF(next);
Original file line number Diff line number Diff line change
@@ -6380,8 +6380,7 @@ convert_sched_param(PyObject *param, struct sched_param *res)
6380 6380 {
6381 6381 long priority;
6382 6382
6383 -PyObject *SchedParamType = _posixstate_global->SchedParamType;
6384 -if (Py_TYPE(param) != (PyTypeObject *)SchedParamType) {
6383 +if (!Py_IS_TYPE(param, (PyTypeObject *)_posixstate_global->SchedParamType)) {
6385 6384 PyErr_SetString(PyExc_TypeError, "must have a sched_param object");
6386 6385 return 0;
6387 6386 }
Original file line number Diff line number Diff line change
@@ -834,7 +834,7 @@ binary_op1(PyObject *v, PyObject *w, const int op_slot)
834 834
835 835 if (Py_TYPE(v)->tp_as_number != NULL)
836 836 slotv = NB_BINOP(Py_TYPE(v)->tp_as_number, op_slot);
837 -if (Py_TYPE(w) != Py_TYPE(v) &&
837 +if (!Py_IS_TYPE(w, Py_TYPE(v)) &&
838 838 Py_TYPE(w)->tp_as_number != NULL) {
839 839 slotw = NB_BINOP(Py_TYPE(w)->tp_as_number, op_slot);
840 840 if (slotw == slotv)
@@ -925,8 +925,7 @@ ternary_op(PyObject *v,
925 925 mw = Py_TYPE(w)->tp_as_number;
926 926 if (mv != NULL)
927 927 slotv = NB_TERNOP(mv, op_slot);
928 -if (Py_TYPE(w) != Py_TYPE(v) &&
929 -mw != NULL) {
928 +if (!Py_IS_TYPE(w, Py_TYPE(v)) && mw != NULL) {
930 929 slotw = NB_TERNOP(mw, op_slot);
931 930 if (slotw == slotv)
932 931 slotw = NULL;
Original file line number Diff line number Diff line change
@@ -657,7 +657,7 @@ do_richcompare(PyThreadState *tstate, PyObject *v, PyObject *w, int op)
657 657 PyObject *res;
658 658 int checked_reverse_op = 0;
659 659
660 -if (Py_TYPE(v) != Py_TYPE(w) &&
660 +if (!Py_IS_TYPE(v, Py_TYPE(w)) &&
661 661 PyType_IsSubtype(Py_TYPE(w), Py_TYPE(v)) &&
662 662 (f = Py_TYPE(w)->tp_richcompare) != NULL) {
663 663 checked_reverse_op = 1;
@@ -1907,7 +1907,7 @@ _Py_GetObjects(PyObject *self, PyObject *args)
1907 1907 return NULL;
1908 1908 for (i = 0; (n == 0 | i < n) && op != &refchain; i++) {
1909 1909 while (op == self | op == args op == res
1910 - (t != NULL && Py_TYPE(op) != (PyTypeObject *) t)) {
1910 + (t != NULL && !Py_IS_TYPE(op, (PyTypeObject *) t))) {
1911 1911 op = op->_ob_next;
1912 1912 if (op == &refchain)
1913 1913 return res;
Original file line number Diff line number Diff line change
@@ -608,7 +608,7 @@ set_repr(PySetObject *so)
608 608 goto done;
609 609 listrepr = tmp;
610 610
611 -if (Py_TYPE(so) != &PySet_Type)
611 +if (!Py_IS_TYPE(so, &PySet_Type))
612 612 result = PyUnicode_FromFormat("%s({%U})",
613 613 Py_TYPE(so)->tp_name,
614 614 listrepr);
Original file line number Diff line number Diff line change
@@ -881,7 +881,7 @@ _PyTuple_Resize(PyObject **pv, Py_ssize_t newsize)
881 881 Py_ssize_t oldsize;
882 882
883 883 v = (PyTupleObject *) *pv;
884 -if (v == NULL | Py_TYPE(v) != &PyTuple_Type
884 +if (v == NULL | !Py_IS_TYPE(v, &PyTuple_Type)
885 885 (Py_SIZE(v) != 0 && Py_REFCNT(v) != 1)) {
886 886 *pv = 0;
887 887 Py_XDECREF(v);
Original file line number Diff line number Diff line change
@@ -1889,7 +1889,7 @@ mro_invoke(PyTypeObject *type)
1889 1889 {
1890 1890 PyObject *mro_result;
1891 1891 PyObject *new_mro;
1892 -int custom = (Py_TYPE(type) != &PyType_Type);
1892 +const int custom = !Py_IS_TYPE(type, &PyType_Type);
1893 1893
1894 1894 if (custom) {
1895 1895 int unbound;
@@ -6191,7 +6191,7 @@ FUNCNAME(PyObject *self, PyObject *other) \
6191 6191 PyThreadState *tstate = _PyThreadState_GET(); \
6192 6192 _Py_static_string(op_id, OPSTR); \
6193 6193 _Py_static_string(rop_id, ROPSTR); \
6194 - int do_other = Py_TYPE(self) != Py_TYPE(other) && \
6194 + int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
6195 6195 Py_TYPE(other)->tp_as_number != NULL && \
6196 6196 Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
6197 6197 if (Py_TYPE(self)->tp_as_number != NULL && \
@@ -7901,7 +7901,7 @@ super_descr_get(PyObject *self, PyObject *obj, PyObject *type)
7901 7901 Py_INCREF(self);
7902 7902 return self;
7903 7903 }
7904 -if (Py_TYPE(su) != &PySuper_Type)
7904 +if (!Py_IS_TYPE(su, &PySuper_Type))
7905 7905 /* If su is an instance of a (strict) subclass of super,
7906 7906 call its type */
7907 7907 return PyObject_CallFunctionObjArgs((PyObject *)Py_TYPE(su),
Original file line number Diff line number Diff line change
@@ -1321,7 +1321,7 @@ _PyErr_WriteUnraisableDefaultHook(PyObject *args)
1321 1321 {
1322 1322 PyThreadState *tstate = _PyThreadState_GET();
1323 1323
1324 -if (Py_TYPE(args) != &UnraisableHookArgsType) {
1324 +if (!Py_IS_TYPE(args, &UnraisableHookArgsType)) {
1325 1325 _PyErr_SetString(tstate, PyExc_TypeError,
1326 1326 "sys.unraisablehook argument type "
1327 1327 "must be UnraisableHookArgs");