11/* Abstract Object Interface (many thanks to Jim Fulton) */
22
33#include "Python.h"
4- #include "pycore_ceval.h" // _Py_EnterRecursiveCall()
4+ #include "pycore_abstract.h" // _PyIndex_Check()
5+ #include "pycore_ceval.h" // _Py_EnterRecursiveCall()
56#include "pycore_pyerrors.h"
67#include "pycore_pystate.h"
78#include <ctype.h>
@@ -160,7 +161,7 @@ PyObject_GetItem(PyObject *o, PyObject *key)
160161
161162 ms = Py_TYPE (o )-> tp_as_sequence ;
162163 if (ms && ms -> sq_item ) {
163- if (PyIndex_Check (key )) {
164+ if (_PyIndex_Check (key )) {
164165 Py_ssize_t key_value ;
165166 key_value = PyNumber_AsSsize_t (key , PyExc_IndexError );
166167 if (key_value == -1 && PyErr_Occurred ())
@@ -176,7 +177,7 @@ PyObject_GetItem(PyObject *o, PyObject *key)
176177 if (PyType_Check (o )) {
177178 PyObject * meth , * result ;
178179 _Py_IDENTIFIER (__class_getitem__ );
179-
180+
180181 // Special case type[int], but disallow other types so str[int] fails
181182 if ((PyTypeObject * )o == & PyType_Type ) {
182183 return Py_GenericAlias (o , key );
@@ -209,7 +210,7 @@ PyObject_SetItem(PyObject *o, PyObject *key, PyObject *value)
209210 return m -> mp_ass_subscript (o , key , value );
210211
211212 if (Py_TYPE (o )-> tp_as_sequence ) {
212- if (PyIndex_Check (key )) {
213+ if (_PyIndex_Check (key )) {
213214 Py_ssize_t key_value ;
214215 key_value = PyNumber_AsSsize_t (key , PyExc_IndexError );
215216 if (key_value == -1 && PyErr_Occurred ())
@@ -241,7 +242,7 @@ PyObject_DelItem(PyObject *o, PyObject *key)
241242 return m -> mp_ass_subscript (o , key , (PyObject * )NULL );
242243
243244 if (Py_TYPE (o )-> tp_as_sequence ) {
244- if (PyIndex_Check (key )) {
245+ if (_PyIndex_Check (key )) {
245246 Py_ssize_t key_value ;
246247 key_value = PyNumber_AsSsize_t (key , PyExc_IndexError );
247248 if (key_value == -1 && PyErr_Occurred ())
@@ -1030,7 +1031,7 @@ static PyObject *
10301031sequence_repeat (ssizeargfunc repeatfunc , PyObject * seq , PyObject * n )
10311032{
10321033 Py_ssize_t count ;
1033- if (PyIndex_Check (n )) {
1034+ if (_PyIndex_Check (n )) {
10341035 count = PyNumber_AsSsize_t (n , PyExc_OverflowError );
10351036 if (count == -1 && PyErr_Occurred ())
10361037 return NULL ;
@@ -1307,15 +1308,16 @@ PyNumber_Absolute(PyObject *o)
13071308 return type_error ("bad operand type for abs(): '%.200s'" , o );
13081309}
13091310
1311+
13101312#undef PyIndex_Check
13111313
13121314int
13131315PyIndex_Check (PyObject * obj )
13141316{
1315- return Py_TYPE (obj )-> tp_as_number != NULL &&
1316- Py_TYPE (obj )-> tp_as_number -> nb_index != NULL ;
1317+ return _PyIndex_Check (obj );
13171318}
13181319
1320+
13191321/* Return a Python int from the object item.
13201322 Raise TypeError if the result is not an int
13211323 or if the object cannot be interpreted as an index.
@@ -1332,7 +1334,7 @@ PyNumber_Index(PyObject *item)
13321334 Py_INCREF (item );
13331335 return item ;
13341336 }
1335- if (!PyIndex_Check (item )) {
1337+ if (!_PyIndex_Check (item )) {
13361338 PyErr_Format (PyExc_TypeError ,
13371339 "'%.200s' object cannot be interpreted "
13381340 "as an integer" , Py_TYPE (item )-> tp_name );
0 commit comments