forked from numpy/numpy-stubs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
3 changed files
with
13 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
__pycache__ | ||
numpy_stubs.egg-info/ | ||
venv | ||
.idea | ||
.idea | ||
**~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import numpy as np | ||
|
||
# Ban setting dtype since mutating the type of the array in place | ||
# makes having ndarray be generic over dtype impossible. Generally | ||
# users should use `ndarray.view` in this situation anyway. See | ||
# | ||
# https://github.com/numpy/numpy-stubs/issues/7 | ||
# | ||
# for more context. | ||
float_array = np.array([1.0]) | ||
float_array.dtype = np.bool_ # E: Property "dtype" defined in "ndarray" is read-only |