[2.7] bpo-34234: Use _PyAnyInt_Check() and _PyAnyInt_CheckExact(). (GH-8479)

diff --git a/Objects/abstract.c b/Objects/abstract.c
index aa92ea9..75c1a10 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -1492,14 +1492,13 @@
     PyObject *result = NULL;
     if (item == NULL)
         return null_error();
-    if (PyInt_Check(item) || PyLong_Check(item)) {
+    if (_PyAnyInt_Check(item)) {
         Py_INCREF(item);
         return item;
     }
     if (PyIndex_Check(item)) {
         result = item->ob_type->tp_as_number->nb_index(item);
-        if (result &&
-            !PyInt_Check(result) && !PyLong_Check(result)) {
+        if (result && !_PyAnyInt_Check(result)) {
             PyErr_Format(PyExc_TypeError,
                          "__index__ returned non-(int,long) " \
                          "(type %.200s)",
@@ -1574,8 +1573,7 @@
             return NULL;
     }
 
-    if (integral && (!PyInt_Check(integral) &&
-                     !PyLong_Check(integral))) {
+    if (integral && !_PyAnyInt_Check(integral)) {
         /* Don't go through tp_as_number->nb_int to avoid
            hitting the classic class fallback to __trunc__. */
         PyObject *int_func = PyObject_GetAttr(integral, int_name);
@@ -1586,8 +1584,7 @@
         Py_DECREF(integral);
         integral = PyEval_CallObject(int_func, NULL);
         Py_DECREF(int_func);
-        if (integral && (!PyInt_Check(integral) &&
-                          !PyLong_Check(integral))) {
+        if (integral && !_PyAnyInt_Check(integral)) {
             goto non_integral_error;
         }
     }
@@ -1632,7 +1629,7 @@
     if (m && m->nb_int) { /* This should include subclasses of int */
         /* Classic classes always take this branch. */
         PyObject *res = m->nb_int(o);
-        if (res && (!PyInt_Check(res) && !PyLong_Check(res))) {
+        if (res && !_PyAnyInt_Check(res)) {
             PyErr_Format(PyExc_TypeError,
                          "__int__ returned non-int (type %.200s)",
                          res->ob_type->tp_name);
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 04c2506..c178d9e 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -35,7 +35,7 @@
         *value = Py_CHARMASK(((PyBytesObject*)arg)->ob_sval[0]);
         return 1;
     }
-    else if (PyInt_Check(arg) || PyLong_Check(arg)) {
+    else if (_PyAnyInt_Check(arg)) {
         face_value = PyLong_AsLong(arg);
     }
     else {
diff --git a/Objects/classobject.c b/Objects/classobject.c
index 5b64578..02d7cfd 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -1009,7 +1009,7 @@
     Py_DECREF(func);
     if (res == NULL)
         return -1;
-    if (PyInt_Check(res) || PyLong_Check(res))
+    if (_PyAnyInt_Check(res))
         /* This already converts a -1 result to -2. */
         outcome = Py_TYPE(res)->tp_hash(res);
     else {
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index a66aa69..d50e4c6 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -423,10 +423,9 @@
 
     /* Py_None is a singleton */
     if (op == Py_None
-       || PyInt_CheckExact(op)
-       || PyLong_CheckExact(op)
-       || PyBool_Check(op)
-       || PyBytes_CheckExact(op)
+        || _PyAnyInt_CheckExact(op)
+        || PyBool_Check(op)
+        || PyBytes_CheckExact(op)
 #ifdef Py_USING_UNICODE
        || PyUnicode_CheckExact(op)
 #endif
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index aaefa2d..871eea3 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -796,7 +796,7 @@
          * NotImplemented.  Only comparisons with core numeric types raise
          * TypeError.
          */
-        if (PyInt_Check(w) || PyLong_Check(w) ||
+        if (_PyAnyInt_Check(w) ||
             PyFloat_Check(w) || PyComplex_Check(w)) {
             PyErr_SetString(PyExc_TypeError,
                             "no ordering relation is defined "
@@ -809,7 +809,7 @@
     assert(PyComplex_Check(v));
     TO_COMPLEX(v, i);
 
-    if (PyInt_Check(w) || PyLong_Check(w)) {
+    if (_PyAnyInt_Check(w)) {
         /* Check for 0.0 imaginary part first to avoid the rich
          * comparison when possible.
          */
diff --git a/Objects/enumobject.c b/Objects/enumobject.c
index 8f86a5b..73b656b 100644
--- a/Objects/enumobject.c
+++ b/Objects/enumobject.c
@@ -31,7 +31,7 @@
             Py_DECREF(en);
             return NULL;
         }
-        assert(PyInt_Check(start) || PyLong_Check(start));
+        assert(_PyAnyInt_Check(start));
         en->en_index = PyInt_AsSsize_t(start);
         if (en->en_index == -1 && PyErr_Occurred()) {
             PyErr_Clear();
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 37dd67e..5954d39 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -428,7 +428,7 @@
         j = PyFloat_AS_DOUBLE(w);
 
     else if (!Py_IS_FINITE(i)) {
-        if (PyInt_Check(w) || PyLong_Check(w))
+        if (_PyAnyInt_Check(w))
             /* If i is an infinity, its magnitude exceeds any
              * finite integer, so it doesn't matter which int we
              * compare i with.  If i is a NaN, similarly.
diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c
index 9daeafc..dc18211 100644
--- a/Objects/sliceobject.c
+++ b/Objects/sliceobject.c
@@ -107,20 +107,20 @@
     if (r->step == Py_None) {
         *step = 1;
     } else {
-        if (!PyInt_Check(r->step) && !PyLong_Check(r->step)) return -1;
+        if (!_PyAnyInt_Check(r->step)) return -1;
         *step = PyInt_AsSsize_t(r->step);
     }
     if (r->start == Py_None) {
         *start = *step < 0 ? length-1 : 0;
     } else {
-        if (!PyInt_Check(r->start) && !PyLong_Check(r->start)) return -1;
+        if (!_PyAnyInt_Check(r->start)) return -1;
         *start = PyInt_AsSsize_t(r->start);
         if (*start < 0) *start += length;
     }
     if (r->stop == Py_None) {
         *stop = *step < 0 ? -1 : length;
     } else {
-        if (!PyInt_Check(r->stop) && !PyLong_Check(r->stop)) return -1;
+        if (!_PyAnyInt_Check(r->stop)) return -1;
         *stop = PyInt_AsSsize_t(r->stop);
         if (*stop < 0) *stop += length;
     }
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 59d22e7..b21afb4 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -4504,7 +4504,7 @@
                 if (PyNumber_Check(v)) {
                     PyObject *iobj=NULL;
 
-                    if (PyInt_Check(v) || (PyLong_Check(v))) {
+                    if (_PyAnyInt_Check(v)) {
                         iobj = v;
                         Py_INCREF(iobj);
                     }
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index d011f7d..8bf04df 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -8628,7 +8628,7 @@
                 if (PyNumber_Check(v)) {
                     PyObject *iobj=NULL;
 
-                    if (PyInt_Check(v) || (PyLong_Check(v))) {
+                    if (_PyAnyInt_Check(v)) {
                         iobj = v;
                         Py_INCREF(iobj);
                     }