Skip to content

Commit 3cb20a0

Browse files
committed
BUG: Fix requirement that user DTypes had to be heaptypes
Requiring heap-types currently does not make sense, because the way to create a new DType is clunky if you were to make a heaptype. This was an initial thought, which panned out inconvenient now, so changing. This has no effect, except for experimental user DTypes when `NUMPY_EXPERIMENTAL_DTYPE_API=1` is used.
1 parent 8eb6555 commit 3cb20a0

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

numpy/core/src/multiarray/descriptor.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,8 +2305,9 @@ arraydescr_new(PyTypeObject *subtype,
23052305
{
23062306
if (subtype != &PyArrayDescr_Type) {
23072307
if (Py_TYPE(subtype) == &PyArrayDTypeMeta_Type &&
2308-
!(PyType_GetFlags(Py_TYPE(subtype)) & Py_TPFLAGS_HEAPTYPE) &&
2309-
(NPY_DT_SLOTS((PyArray_DTypeMeta *)subtype)) != NULL) {
2308+
(NPY_DT_SLOTS((PyArray_DTypeMeta *)subtype)) != NULL &&
2309+
!NPY_DT_is_legacy((PyArray_DTypeMeta *)subtype) &&
2310+
subtype->tp_new != PyArrayDescr_Type.tp_new) {
23102311
/*
23112312
* Appears to be a properly initialized user DType. Allocate
23122313
* it and initialize the main part as best we can.
@@ -2333,7 +2334,9 @@ arraydescr_new(PyTypeObject *subtype,
23332334
}
23342335
/* The DTypeMeta class should prevent this from happening. */
23352336
PyErr_Format(PyExc_SystemError,
2336-
"'%S' must not inherit np.dtype.__new__().", subtype);
2337+
"'%S' must not inherit np.dtype.__new__(). User DTypes should "
2338+
"currently call `PyArrayDescr_Type.tp_new` from their new.",
2339+
subtype);
23372340
return NULL;
23382341
}
23392342

0 commit comments

Comments
 (0)