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

Code before:
    }
    else {
        /* Free old dimensions and strides */
        npy_free_cache_dim_array(self);
        ((PyArrayObject_fields *)self)->nd = 0;
        ((PyArrayObject_fields *)self)->dimensions = NULL;
        ((PyArrayObject_fields *)self)->strides = NULL;
    }

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

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

    /* Deprecated NumPy 2.4, 2025-07-29 */
    if (DEPRECATE("Setting the shape on a NumPy array has been deprecated"
                  " in NumPy 2.4.\nAs an alternative, you can create a new"
                  " view using np.reshape (with copy=False if needed)."
                 ) < 0 ) {
            return -1;
    }

    return array_shape_set_internal(self, val);
}

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"

Review comment (suggestion):
```suggestion
    /* Deprecated NumPy 2.5, 2026-01-05 */
    if (DEPRECATE("Setting the shape on a NumPy array has been deprecated"
                  " in NumPy 2.5.\nAs an alternative, you can create a new"
```

Code after:
    }
    else {
        /* Free old dimensions and strides */
        npy_free_cache_dim_array(self);
        ((PyArrayObject_fields *)self)->nd = 0;
        ((PyArrayObject_fields *)self)->dimensions = NULL;
        ((PyArrayObject_fields *)self)->strides = NULL;
    }

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

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

    /* Deprecated NumPy 2.5, 2026-01-05 */
    if (DEPRECATE("Setting the shape on a NumPy array has been deprecated"
                  " in NumPy 2.5.\nAs an alternative, you can create a new"
                  " view using np.reshape (with copy=False if needed)."
                 ) < 0 ) {
            return -1;
    }

    return array_shape_set_internal(self, val);
}

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"