Introducing the metaclass without a canonical top-level name broke
pickling of `type(np.dtype(...))` (which was always just `np.dtype`).
While a better solution will likely be possible by making the
DTypes HeapTypes and this solution may not work for all imaginable
cases (i.e. it is plausible for a dtype to not have a scalar type
associated), using a `copyreg` registration for the metaclass
surprisingly works without any issues and seems like the simplest
solution right now.
Closes numpygh-16692, numpygh-18325
Backport of #18332.
Introducing the metaclass without a canonical top-level name broke
pickling of type(np.dtype(...)) (which was always just np.dtype).
While a better solution will likely be possible by making the
DTypes HeapTypes and this solution may not work for all imaginable
cases (i.e. it is plausible for a dtype to not have a scalar type
associated), using a copyreg registration for the metaclass
surprisingly works without any issues and seems like the simplest
solution right now.
Closes gh-16692, gh-18325