* Get an object's __array_function__ method in the fastest way possible. * Never raises an exception. Returns NULL if the method doesn't exist. */
| 27 | * Never raises an exception. Returns NULL if the method doesn't exist. |
| 28 | */ |
| 29 | static PyObject * |
| 30 | get_array_function(PyObject *obj) |
| 31 | { |
| 32 | static PyObject *ndarray_array_function = NULL; |
| 33 | |
| 34 | if (ndarray_array_function == NULL) { |
| 35 | ndarray_array_function = get_ndarray_array_function(); |
| 36 | } |
| 37 | |
| 38 | /* Fast return for ndarray */ |
| 39 | if (PyArray_CheckExact(obj)) { |
| 40 | Py_INCREF(ndarray_array_function); |
| 41 | return ndarray_array_function; |
| 42 | } |
| 43 | |
| 44 | PyObject *array_function = PyArray_LookupSpecial(obj, npy_ma_str_array_function); |
| 45 | if (array_function == NULL && PyErr_Occurred()) { |
| 46 | PyErr_Clear(); /* TODO[gh-14801]: propagate crashes during attribute access? */ |
| 47 | } |
| 48 | |
| 49 | return array_function; |
| 50 | } |
| 51 | |
| 52 | |
| 53 | /* |
no test coverage detected