Skip to content

Commit 9969a5d

Browse files
authored
make zdtype abstract methods raise notimplementederror (#3251)
* make zdtype abstract methods raise notimplementederror * changelog * exclude notimplementederrors from coverage * cover missing methods
1 parent 18f41d4 commit 9969a5d

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

changes/3251.fix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensure that all abstract methods of ``ZDType`` raise a ``NotImplementedError`` when invoked.

src/zarr/core/dtype/wrapper.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ def from_native_dtype(cls: type[Self], dtype: TBaseDType) -> Self:
102102
"""
103103
Create a ZDType instance from a native data type.
104104
105-
The base implementation first performs a type check via ``cls._check_native_dtype``.
106-
If that type check succeeds, the ZDType class instance is created.
107-
108105
This method is used when taking a user-provided native data type, like a NumPy data type,
109106
and creating the corresponding ZDType instance from them.
110107
@@ -123,7 +120,7 @@ def from_native_dtype(cls: type[Self], dtype: TBaseDType) -> Self:
123120
TypeError
124121
If the native data type is not consistent with the wrapped data type.
125122
"""
126-
...
123+
raise NotImplementedError # pragma: no cover
127124

128125
@abstractmethod
129126
def to_native_dtype(self: Self) -> TDType_co:
@@ -135,15 +132,17 @@ def to_native_dtype(self: Self) -> TDType_co:
135132
TDType
136133
The native data type wrapped by this ZDType.
137134
"""
138-
...
135+
raise NotImplementedError # pragma: no cover
139136

140137
@classmethod
141138
@abstractmethod
142-
def _from_json_v2(cls: type[Self], data: DTypeJSON) -> Self: ...
139+
def _from_json_v2(cls: type[Self], data: DTypeJSON) -> Self:
140+
raise NotImplementedError # pragma: no cover
143141

144142
@classmethod
145143
@abstractmethod
146-
def _from_json_v3(cls: type[Self], data: DTypeJSON) -> Self: ...
144+
def _from_json_v3(cls: type[Self], data: DTypeJSON) -> Self:
145+
raise NotImplementedError # pragma: no cover
147146

148147
@classmethod
149148
def from_json(cls: type[Self], data: DTypeJSON, *, zarr_format: ZarrFormat) -> Self:
@@ -190,7 +189,7 @@ def to_json(self, zarr_format: ZarrFormat) -> DTypeSpec_V2 | DTypeSpec_V3:
190189
DTypeJSON_V2 | DTypeJSON_V3
191190
The JSON-serializable representation of the wrapped data type
192191
"""
193-
...
192+
raise NotImplementedError # pragma: no cover
194193

195194
@abstractmethod
196195
def _check_scalar(self, data: object) -> bool:
@@ -207,7 +206,7 @@ def _check_scalar(self, data: object) -> bool:
207206
Bool
208207
True if the object is valid, False otherwise.
209208
"""
210-
...
209+
raise NotImplementedError # pragma: no cover
211210

212211
@abstractmethod
213212
def cast_scalar(self, data: object) -> TScalar_co:
@@ -227,6 +226,7 @@ def cast_scalar(self, data: object) -> TScalar_co:
227226
TScalar
228227
The cast value.
229228
"""
229+
raise NotImplementedError # pragma: no cover
230230

231231
@abstractmethod
232232
def default_scalar(self) -> TScalar_co:
@@ -242,7 +242,7 @@ def default_scalar(self) -> TScalar_co:
242242
TScalar
243243
The default value for this data type.
244244
"""
245-
...
245+
raise NotImplementedError # pragma: no cover
246246

247247
@abstractmethod
248248
def from_json_scalar(self: Self, data: JSON, *, zarr_format: ZarrFormat) -> TScalar_co:
@@ -262,7 +262,7 @@ def from_json_scalar(self: Self, data: JSON, *, zarr_format: ZarrFormat) -> TSca
262262
TScalar
263263
The deserialized scalar value.
264264
"""
265-
...
265+
raise NotImplementedError # pragma: no cover
266266

267267
@abstractmethod
268268
def to_json_scalar(self, data: object, *, zarr_format: ZarrFormat) -> JSON:
@@ -285,7 +285,7 @@ def to_json_scalar(self, data: object, *, zarr_format: ZarrFormat) -> JSON:
285285
JSON
286286
The JSON-serialized scalar.
287287
"""
288-
...
288+
raise NotImplementedError # pragma: no cover
289289

290290

291291
def scalar_failed_type_check_msg(

0 commit comments

Comments
 (0)