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

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 {