Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

MAINT: ban setting ndarray.dtype #47

Merged
merged 1 commit into from
Mar 30, 2020
Merged

Conversation

person142
Copy link
Member

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
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
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.
@shoyer shoyer merged commit ba67281 into numpy:master Mar 30, 2020
@shoyer
Copy link
Member

shoyer commented Mar 30, 2020

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants