Repository: numpy/numpy
File: numpy/_core/src/multiarray/getset.c (C)

Code before:
        ((PyArrayObject_fields *)self)->strides = NULL;
    }

    Py_DECREF(ret);
    PyArray_UpdateFlags(self, NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_F_CONTIGUOUS);
    return 0;
}


static PyObject *
array_strides_get(PyArrayObject *self, void *NPY_UNUSED(ignored))
{
    return PyArray_IntTupleFromIntp(PyArray_NDIM(self), PyArray_STRIDES(self));
}

static int
array_strides_set(PyArrayObject *self, PyObject *obj, void *NPY_UNUSED(ignored))
{
    if (obj == NULL) {
        PyErr_SetString(PyExc_AttributeError,
                "Cannot delete array strides");
        return -1;
    }

    /* Deprecated NumPy 2.4, 2025-05-11 */
    if( DEPRECATE("Setting the strides on a NumPy array has been deprecated in NumPy 2.4.\n"
                  "As an alternative, you can create a new view using np.lib.stride_tricks.as_strided."
                 ) < 0 ) {
        return -1;
    }

    PyArray_Dims newstrides = {NULL, -1};
    PyArrayObject *new;
    npy_intp numbytes = 0;
    npy_intp offset = 0;
    npy_intp lower_offset = 0;
    npy_intp upper_offset = 0;
    Py_buffer view;

    if (!PyArray_OptionalIntpConverter(obj, &newstrides) ||
        newstrides.len == -1) {
        PyErr_SetString(PyExc_TypeError, "invalid strides");
        return -1;
    }
    if (newstrides.len != PyArray_NDIM(self)) {
        PyErr_Format(PyExc_ValueError, "strides must be "       \
                     " same length as shape (%d)", PyArray_NDIM(self));
        goto fail;
    }
    new = self;
    while(PyArray_BASE(new) && PyArray_Check(PyArray_BASE(new))) {

Review comment (suggestion):
```suggestion
    if (DEPRECATE("Setting the strides on a NumPy array has been deprecated in NumPy 2.4.\n"
```

Code after:
        ((PyArrayObject_fields *)self)->strides = NULL;
    }

    Py_DECREF(ret);
    PyArray_UpdateFlags(self, NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_F_CONTIGUOUS);
    return 0;
}


static PyObject *
array_strides_get(PyArrayObject *self, void *NPY_UNUSED(ignored))
{
    return PyArray_IntTupleFromIntp(PyArray_NDIM(self), PyArray_STRIDES(self));
}

static int
array_strides_set(PyArrayObject *self, PyObject *obj, void *NPY_UNUSED(ignored))
{
    if (obj == NULL) {
        PyErr_SetString(PyExc_AttributeError,
                "Cannot delete array strides");
        return -1;
    }

    /* Deprecated NumPy 2.4, 2025-05-11 */
    if (DEPRECATE("Setting the strides on a NumPy array has been deprecated in NumPy 2.4.\n"
                  "As an alternative, you can create a new view using np.lib.stride_tricks.as_strided."
                 ) < 0 ) {
        return -1;
    }

    PyArray_Dims newstrides = {NULL, -1};
    PyArrayObject *new;
    npy_intp numbytes = 0;
    npy_intp offset = 0;
    npy_intp lower_offset = 0;
    npy_intp upper_offset = 0;
    Py_buffer view;

    if (!PyArray_OptionalIntpConverter(obj, &newstrides) ||
        newstrides.len == -1) {
        PyErr_SetString(PyExc_TypeError, "invalid strides");
        return -1;
    }
    if (newstrides.len != PyArray_NDIM(self)) {
        PyErr_Format(PyExc_ValueError, "strides must be "       \
                     " same length as shape (%d)", PyArray_NDIM(self));
        goto fail;
    }
    new = self;
    while(PyArray_BASE(new) && PyArray_Check(PyArray_BASE(new))) {