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

MAINT: ban setting ndarray.dtype - #47

Merged
shoyer merged 1 commit into
numpy:masterfrom
person142:no-setting-dtype
Mar 30, 2020
Merged

shoyer merged 1 commit into
numpy:masterfrom
person142:no-setting-dtype

Conversation

@person142

Copy link
Copy Markdown
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

shoyer commented Mar 30, 2020

Copy link
Copy Markdown
Member

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