#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
(__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
__Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) : \
- __Pyx_GetItemInt_Generic(o, to_py_func(i)))
+ (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), NULL) : \
+ __Pyx_GetItemInt_Generic(o, to_py_func(i))))
{{for type in ['List', 'Tuple']}}
#define __Pyx_GetItemInt_{{type}}(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
#define __Pyx_SetItemInt(o, i, v, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
(__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
__Pyx_SetItemInt_Fast(o, (Py_ssize_t)i, v, is_list, wraparound, boundscheck) : \
- __Pyx_SetItemInt_Generic(o, to_py_func(i), v))
+ (is_list ? (PyErr_SetString(PyExc_IndexError, "list assignment index out of range"), -1) : \
+ __Pyx_SetItemInt_Generic(o, to_py_func(i), v)))
static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v);
static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v,
#define __Pyx_DelItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
(__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
__Pyx_DelItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound) : \
- __Pyx_DelItem_Generic(o, to_py_func(i)))
+ (is_list ? (PyErr_SetString(PyExc_IndexError, "list assignment index out of range"), -1) : \
+ __Pyx_DelItem_Generic(o, to_py_func(i))))
static CYTHON_INLINE int __Pyx_DelItem_Generic(PyObject *o, PyObject *j);
static CYTHON_INLINE int __Pyx_DelItemInt_Fast(PyObject *o, Py_ssize_t i,
return o[i]
+def del_index_list(list L, Py_ssize_t index):
+ """
+ >>> del_index_list(list(range(4)), 0)
+ [1, 2, 3]
+ >>> del_index_list(list(range(4)), 1)
+ [0, 2, 3]
+ >>> del_index_list(list(range(4)), -1)
+ [0, 1, 2]
+ >>> del_index_list(list(range(4)), py_maxsize)
+ Traceback (most recent call last):
+ IndexError: list assignment index out of range
+ >>> del_index_list(list(range(4)), -py_maxsize)
+ Traceback (most recent call last):
+ IndexError: list assignment index out of range
+ """
+ del L[index]
+ return L
+
+
+def set_index_list(list L, Py_ssize_t index):
+ """
+ >>> set_index_list(list(range(4)), 0)
+ [5, 1, 2, 3]
+ >>> set_index_list(list(range(4)), 1)
+ [0, 5, 2, 3]
+ >>> set_index_list(list(range(4)), -1)
+ [0, 1, 2, 5]
+ >>> set_index_list(list(range(4)), py_maxsize)
+ Traceback (most recent call last):
+ IndexError: list assignment index out of range
+ >>> set_index_list(list(range(4)), -py_maxsize)
+ Traceback (most recent call last):
+ IndexError: list assignment index out of range
+ """
+ L[index] = 5
+ return L
+
+
# These make sure that our fast indexing works with large and unsigned types.
def test_unsigned_long():