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
merged 1 commit into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
__pycache__
numpy_stubs.egg-info/
venv
.idea
.idea
**~
2 changes: 0 additions & 2 deletions numpy-stubs/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,6 @@ class ndarray(_ArrayOrScalarCommon, Iterable, Sized, Container):
) -> ndarray: ...
@property
def dtype(self) -> _Dtype: ...
@dtype.setter
def dtype(self, value: _DtypeLike): ...
@property
def ctypes(self) -> _ctypes: ...
@property
Expand Down
11 changes: 11 additions & 0 deletions tests/fail/ndarray.py
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