From a9385af68e1217a93cb6d025862ff74758bd1468 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk <21087696+oleksandr-pavlyk@users.noreply.github.com> Date: Tue, 14 Jan 2025 08:25:25 -0600 Subject: [PATCH] Make copy argument of __array__ method keyword-only --- dpctl/tensor/_usmarray.pyx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/dpctl/tensor/_usmarray.pyx b/dpctl/tensor/_usmarray.pyx index 150f0b3b65..668e17bd79 100644 --- a/dpctl/tensor/_usmarray.pyx +++ b/dpctl/tensor/_usmarray.pyx @@ -1552,8 +1552,15 @@ cdef class usm_ndarray: def __repr__(self): return usm_ndarray_repr(self) - def __array__(self, dtype=None, copy=None): - "NumPy array protocol" + def __array__(self, dtype=None, /, *, copy=None): + """NumPy's array protocol method to disallow implicit conversion. + + Without this definition, `numpy.asarray(usm_ar)` converts + usm_ndarray instance into NumPy array with data type `object` + and every element being 0d usm_ndarray. + + https://github.com/IntelPython/dpctl/pull/1384#issuecomment-1707212972 + """ raise TypeError( "Implicit conversion to a NumPy array is not allowed. " "Use `dpctl.tensor.asnumpy` to copy data from this "