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

Code before:
        copyswap(selfit->dataptr, arrit->dataptr, swap, self);
        PyArray_ITER_NEXT(selfit);
        PyArray_ITER_NEXT(arrit);
        if (arrit->index == arrit->size) {
            PyArray_ITER_RESET(arrit);
        }
    }
    retval = 0;

 exit:
    Py_XDECREF(selfit);
    Py_XDECREF(arrit);
    Py_XDECREF(arr);
    return retval;
}

static PyObject *
array_transpose_get(PyArrayObject *self, void *NPY_UNUSED(ignored))
{
    int ndim = PyArray_NDIM(self);
    if (ndim != 2) {
        if (PyErr_WarnFormat(PyExc_UserWarning, 1,
                "In the future `.T` property will be supported for "
                "2-dim arrays only. Received %d-dim array. Either "
                "`np.permute_dims(arr, range(arr.ndim)[::-1])` "
                "(compatible with the Array API) or `arr.transpose()` "
                "should be used instead.",
                ndim) < 0) {
            return NULL;
        }
    }
    return PyArray_Transpose(self, NULL);
}

static PyObject *
array_matrix_transpose_get(PyArrayObject *self, void *NPY_UNUSED(ignored))
{
    return PyArray_MatrixTranspose(self);
}

static PyObject *
array_ptp(PyArrayObject *self, void *NPY_UNUSED(ignored))
{
    PyErr_SetString(PyExc_AttributeError,
                    "`ptp` was removed from the ndarray class in NumPy 2.0. "
                    "Use np.ptp(arr, ...) instead.");
    return NULL;
}

static PyObject *
array_newbyteorder(PyArrayObject *self, PyObject *args)

Review comment (security):
I would delete the note and at least re-order this.  It nudges users to something less convenient for what seems very little reason to me.
A user who needs array API is a library author and will already not use `.T` here anyway.

It may be good to note that `.mT` exists to swap the last two axes only (If just to increase awareness).

Code after:
        copyswap(selfit->dataptr, arrit->dataptr, swap, self);
        PyArray_ITER_NEXT(selfit);
        PyArray_ITER_NEXT(arrit);
        if (arrit->index == arrit->size) {
            PyArray_ITER_RESET(arrit);
        }
    }
    retval = 0;

 exit:
    Py_XDECREF(selfit);
    Py_XDECREF(arrit);
    Py_XDECREF(arr);
    return retval;
}

static PyObject *
array_transpose_get(PyArrayObject *self, void *NPY_UNUSED(ignored))
{
    int ndim = PyArray_NDIM(self);
    if (ndim != 2) {
        /* Deprecated 2025-04-19, NumPy 2.3 */
        if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
                "In the future, the `.T` property will be supported for "
                "2-dimensional arrays only. Received %d-dimensional "
                "array. Either `arr.transpose()` or `.mT` (which swaps "
                "the last two axes only) should be used instead."
                "(Deprecated NumPy 2.3)", ndim) < 0) {
            return NULL;
        }
    }
    return PyArray_Transpose(self, NULL);
}

static PyObject *
array_matrix_transpose_get(PyArrayObject *self, void *NPY_UNUSED(ignored))
{
    return PyArray_MatrixTranspose(self);
}

static PyObject *
array_ptp(PyArrayObject *self, void *NPY_UNUSED(ignored))
{
    PyErr_SetString(PyExc_AttributeError,
                    "`ptp` was removed from the ndarray class in NumPy 2.0. "
                    "Use np.ptp(arr, ...) instead.");
    return NULL;
}

static PyObject *
array_newbyteorder(PyArrayObject *self, PyObject *args)