diff options
author | Andy Lester <andy@petdance.com> | 2020-03-06 22:53:17 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-06 22:53:17 (GMT) |
commit | 557287075c264d2458cd3e1b45e9b8ee5341e0a1 (patch) | |
tree | 6c34331fdbf74476b60b1e32972e360af4985ab6 /Objects | |
parent | e59334ebc9308b0f3ad048ef293c6b49e6456d1a (diff) | |
download | cpython-557287075c264d2458cd3e1b45e9b8ee5341e0a1.zip cpython-557287075c264d2458cd3e1b45e9b8ee5341e0a1.tar.gz cpython-557287075c264d2458cd3e1b45e9b8ee5341e0a1.tar.bz2 |
bpo-39573: Use Py_IS_TYPE() macro to check for types (GH-18809)
Co-authored-by: Victor Stinner <vstinner@python.org>
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/abstract.c | 5 | ||||
-rw-r--r-- | Objects/object.c | 4 | ||||
-rw-r--r-- | Objects/setobject.c | 2 | ||||
-rw-r--r-- | Objects/tupleobject.c | 2 | ||||
-rw-r--r-- | Objects/typeobject.c | 6 |
5 files changed, 9 insertions, 10 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c index 454e0da..accd72d 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -834,7 +834,7 @@ binary_op1(PyObject *v, PyObject *w, const int op_slot) if (Py_TYPE(v)->tp_as_number != NULL) slotv = NB_BINOP(Py_TYPE(v)->tp_as_number, op_slot); - if (Py_TYPE(w) != Py_TYPE(v) && + if (!Py_IS_TYPE(w, Py_TYPE(v)) && Py_TYPE(w)->tp_as_number != NULL) { slotw = NB_BINOP(Py_TYPE(w)->tp_as_number, op_slot); if (slotw == slotv) @@ -925,8 +925,7 @@ ternary_op(PyObject *v, mw = Py_TYPE(w)->tp_as_number; if (mv != NULL) slotv = NB_TERNOP(mv, op_slot); - if (Py_TYPE(w) != Py_TYPE(v) && - mw != NULL) { + if (!Py_IS_TYPE(w, Py_TYPE(v)) && mw != NULL) { slotw = NB_TERNOP(mw, op_slot); if (slotw == slotv) slotw = NULL; diff --git a/Objects/object.c b/Objects/object.c index 8314a08..bb47cfa 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -657,7 +657,7 @@ do_richcompare(PyThreadState *tstate, PyObject *v, PyObject *w, int op) PyObject *res; int checked_reverse_op = 0; - if (Py_TYPE(v) != Py_TYPE(w) && + if (!Py_IS_TYPE(v, Py_TYPE(w)) && PyType_IsSubtype(Py_TYPE(w), Py_TYPE(v)) && (f = Py_TYPE(w)->tp_richcompare) != NULL) { checked_reverse_op = 1; @@ -1907,7 +1907,7 @@ _Py_GetObjects(PyObject *self, PyObject *args) return NULL; for (i = 0; (n == 0 || i < n) && op != &refchain; i++) { while (op == self || op == args || op == res || op == t || - (t != NULL && Py_TYPE(op) != (PyTypeObject *) t)) { + (t != NULL && !Py_IS_TYPE(op, (PyTypeObject *) t))) { op = op->_ob_next; if (op == &refchain) return res; diff --git a/Objects/setobject.c b/Objects/setobject.c index bb7c0b8..43fa5d1 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -608,7 +608,7 @@ set_repr(PySetObject *so) goto done; listrepr = tmp; - if (Py_TYPE(so) != &PySet_Type) + if (!Py_IS_TYPE(so, &PySet_Type)) result = PyUnicode_FromFormat("%s({%U})", Py_TYPE(so)->tp_name, listrepr); diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 92374cc..52ecb54 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -881,7 +881,7 @@ _PyTuple_Resize(PyObject **pv, Py_ssize_t newsize) Py_ssize_t oldsize; v = (PyTupleObject *) *pv; - if (v == NULL || Py_TYPE(v) != &PyTuple_Type || + if (v == NULL || !Py_IS_TYPE(v, &PyTuple_Type) || (Py_SIZE(v) != 0 && Py_REFCNT(v) != 1)) { *pv = 0; Py_XDECREF(v); diff --git a/Objects/typeobject.c b/Objects/typeobject.c index cf749ef..ec8dc19 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -1889,7 +1889,7 @@ mro_invoke(PyTypeObject *type) { PyObject *mro_result; PyObject *new_mro; - int custom = (Py_TYPE(type) != &PyType_Type); + const int custom = !Py_IS_TYPE(type, &PyType_Type); if (custom) { int unbound; @@ -6191,7 +6191,7 @@ FUNCNAME(PyObject *self, PyObject *other) \ PyThreadState *tstate = _PyThreadState_GET(); \ _Py_static_string(op_id, OPSTR); \ _Py_static_string(rop_id, ROPSTR); \ - int do_other = Py_TYPE(self) != Py_TYPE(other) && \ + int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \ Py_TYPE(other)->tp_as_number != NULL && \ Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \ if (Py_TYPE(self)->tp_as_number != NULL && \ @@ -7901,7 +7901,7 @@ super_descr_get(PyObject *self, PyObject *obj, PyObject *type) Py_INCREF(self); return self; } - if (Py_TYPE(su) != &PySuper_Type) + if (!Py_IS_TYPE(su, &PySuper_Type)) /* If su is an instance of a (strict) subclass of super, call its type */ return PyObject_CallFunctionObjArgs((PyObject *)Py_TYPE(su), |