Skip to content

Commit c76be48

Browse files
committed
fix mypy for ScalarWrapper
1 parent f1cb6e1 commit c76be48

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

src/zarr/core/buffer/core.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,13 @@ def view(self, dtype: npt.DTypeLike) -> Self:
154154
def astype(
155155
self, dtype: npt.DTypeLike, order: Literal["K", "A", "C", "F"] = "K", *, copy: bool = True
156156
) -> Self:
157-
if copy:
158-
return ScalarWrapper(dtype.type(self._value))
159-
self._value = dtype.type(self._value)
160-
return self
157+
raise TypeError("ScalarWrapper object has no astype()")
161158

162159
def fill(self, value: Any) -> None:
163160
self._value = value
164161

165162
def copy(self) -> Self:
166-
return ScalarWrapper(self._value)
163+
return self.__class__(self._value)
167164

168165
def transpose(self, axes: SupportsIndex | Sequence[SupportsIndex] | None = None) -> Self:
169166
return self
@@ -175,7 +172,7 @@ def all(self) -> bool:
175172
return bool(self._value)
176173

177174
def __eq__(self, other: object) -> Self:
178-
return ScalarWrapper(self._value == other)
175+
return self.__class__(self._value == other)
179176

180177
def __repr__(self) -> str:
181178
return f"ScalarWrapper({self._value!r})"
@@ -208,7 +205,7 @@ def __neg__(self) -> Any:
208205
return -self._value
209206

210207
def __abs__(self) -> Any:
211-
if isinstance(self._value, (int, float, complex)):
208+
if hasattr(self._value, "__abs__"):
212209
return abs(self._value)
213210
raise TypeError(f"bad operand type for abs(): '{self._value.__class__.__name__}'")
214211

tests/test_buffer.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,8 @@ async def test_async_array_prototype() -> None:
6262
prototype=my_prototype,
6363
)
6464
got = await a.getitem(selection=(slice(0, 9), slice(0, 9)), prototype=my_prototype)
65-
# ignoring a mypy error here that TestNDArrayLike doesn't meet the NDArrayLike protocol
66-
# The test passes, so it clearly does.
67-
assert isinstance(got, TestNDArrayLike) # type: ignore[unreachable]
68-
assert np.array_equal(expect, got) # type: ignore[unreachable]
65+
assert isinstance(got, TestNDArrayLike)
66+
assert np.array_equal(expect, got)
6967

7068

7169
@gpu_test
@@ -115,10 +113,8 @@ async def test_codecs_use_of_prototype() -> None:
115113
prototype=my_prototype,
116114
)
117115
got = await a.getitem(selection=(slice(0, 10), slice(0, 10)), prototype=my_prototype)
118-
# ignoring a mypy error here that TestNDArrayLike doesn't meet the NDArrayLike protocol
119-
# The test passes, so it clearly does.
120-
assert isinstance(got, TestNDArrayLike) # type: ignore[unreachable]
121-
assert np.array_equal(expect, got) # type: ignore[unreachable]
116+
assert isinstance(got, TestNDArrayLike)
117+
assert np.array_equal(expect, got)
122118

123119

124120
@gpu_test

0 commit comments

Comments
 (0)