Though this is valid NumPy, users should be using ndarray.view
instead of setting the dtype, and setting the dtype prevents sensibly
making ndarray generic over dtype because of situations like this:
x = np.ones((2,), dtype=np.int64) # type is ndarray[np.int64]
x.dtype = np.bool_ # What is the type now?
If someone really wants to do this, they will now have add an ignore,
which should make it clear that type safety is going out the window.
See discussion in https://github.com/numpy/numpy-stubs/issues/7.
Though this is valid NumPy, users should be using
ndarray.view
instead of setting the dtype, and setting the dtype prevents sensibly makingndarray
generic over dtype because of situations like this:If someone really wants to do this, they will now have add an ignore, which should make it clear that type safety is going out the window.