Skip to content

Commit d408b9d

Browse files
committed
make datatype configuration typeddict readonly
1 parent bec9512 commit d408b9d

File tree

10 files changed

+26
-22
lines changed

10 files changed

+26
-22
lines changed

src/zarr/core/common.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
overload,
2020
)
2121

22+
from typing_extensions import ReadOnly
23+
2224
from zarr.core.config import config as zarr_config
2325

2426
if TYPE_CHECKING:
@@ -48,8 +50,8 @@
4850

4951

5052
class NamedConfig(TypedDict, Generic[TName, TConfig]):
51-
name: TName
52-
configuration: TConfig
53+
name: ReadOnly[TName]
54+
configuration: ReadOnly[TConfig]
5355

5456

5557
def product(tup: ChunkCoords) -> int:

src/zarr/core/dtype/common.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
TypeVar,
1414
)
1515

16+
from typing_extensions import ReadOnly
17+
1618
from zarr.core.common import NamedConfig
1719

1820
EndiannessStr = Literal["little", "big"]
@@ -55,8 +57,8 @@
5557

5658

5759
class DTypeConfig_V2(TypedDict, Generic[TDTypeNameV2_co, TObjectCodecID_co]):
58-
name: TDTypeNameV2_co
59-
object_codec_id: TObjectCodecID_co
60+
name: ReadOnly[TDTypeNameV2_co]
61+
object_codec_id: ReadOnly[TObjectCodecID_co]
6062

6163

6264
DTypeSpec_V2 = DTypeConfig_V2[DTypeName_V2, None | str]

src/zarr/core/dtype/npy/bool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def _from_json_v3(cls: type[Self], data: DTypeJSON) -> Self:
176176
msg = f"Invalid JSON representation of {cls.__name__}. Got {data!r}, expected the string {cls._zarr_v3_name!r}"
177177
raise DataTypeValidationError(msg)
178178

179-
@overload # type: ignore[override]
179+
@overload
180180
def to_json(self, zarr_format: Literal[2]) -> DTypeConfig_V2[Literal["|b1"], None]: ...
181181

182182
@overload

src/zarr/core/dtype/npy/bytes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def _from_json_v3(cls, data: DTypeJSON) -> Self:
224224
msg = f"Invalid JSON representation of {cls.__name__}. Got {data!r}, expected the string {cls._zarr_v3_name!r}"
225225
raise DataTypeValidationError(msg)
226226

227-
@overload # type: ignore[override]
227+
@overload
228228
def to_json(self, zarr_format: Literal[2]) -> DTypeConfig_V2[str, None]: ...
229229

230230
@overload
@@ -637,7 +637,7 @@ def _from_json_v3(cls, data: DTypeJSON) -> Self:
637637
msg = f"Invalid JSON representation of {cls.__name__}. Got {data!r}, expected the string {cls._zarr_v3_name!r}"
638638
raise DataTypeValidationError(msg)
639639

640-
@overload # type: ignore[override]
640+
@overload
641641
def to_json(self, zarr_format: Literal[2]) -> DTypeConfig_V2[str, None]: ...
642642

643643
@overload
@@ -985,7 +985,7 @@ def _from_json_v3(cls, data: DTypeJSON) -> Self:
985985
msg = f"Invalid JSON representation of {cls.__name__}. Got {data!r}, expected the string {cls._zarr_v3_name!r}"
986986
raise DataTypeValidationError(msg)
987987

988-
@overload # type: ignore[override]
988+
@overload
989989
def to_json(
990990
self, zarr_format: Literal[2]
991991
) -> DTypeConfig_V2[Literal["|O"], Literal["vlen-bytes"]]: ...

src/zarr/core/dtype/npy/complex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def _from_json_v3(cls, data: DTypeJSON) -> Self:
185185
msg = f"Invalid JSON representation of {cls.__name__}. Got {data!r}, expected {cls._zarr_v3_name}."
186186
raise DataTypeValidationError(msg)
187187

188-
@overload # type: ignore[override]
188+
@overload
189189
def to_json(self, zarr_format: Literal[2]) -> DTypeConfig_V2[str, None]: ...
190190

191191
@overload

src/zarr/core/dtype/npy/float.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def _from_json_v3(cls, data: DTypeJSON) -> Self:
161161
msg = f"Invalid JSON representation of {cls.__name__}. Got {data!r}, expected {cls._zarr_v3_name}."
162162
raise DataTypeValidationError(msg)
163163

164-
@overload # type: ignore[override]
164+
@overload
165165
def to_json(self, zarr_format: Literal[2]) -> DTypeConfig_V2[str, None]: ...
166166

167167
@overload

src/zarr/core/dtype/npy/int.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ def _from_json_v3(cls, data: DTypeJSON) -> Self:
343343
msg = f"Invalid JSON representation of {cls.__name__}. Got {data!r}, expected the string {cls._zarr_v3_name!r}"
344344
raise DataTypeValidationError(msg)
345345

346-
@overload # type: ignore[override]
346+
@overload
347347
def to_json(self, zarr_format: Literal[2]) -> DTypeConfig_V2[Literal["|i1"], None]: ...
348348

349349
@overload
@@ -484,7 +484,7 @@ def _from_json_v3(cls, data: DTypeJSON) -> Self:
484484
msg = f"Invalid JSON representation of {cls.__name__}. Got {data!r}, expected the string {cls._zarr_v3_name!r}"
485485
raise DataTypeValidationError(msg)
486486

487-
@overload # type: ignore[override]
487+
@overload
488488
def to_json(self, zarr_format: Literal[2]) -> DTypeConfig_V2[Literal["|u1"], None]: ...
489489

490490
@overload
@@ -646,7 +646,7 @@ def _from_json_v3(cls, data: DTypeJSON) -> Self:
646646
msg = f"Invalid JSON representation of {cls.__name__}. Got {data!r}, expected the string {cls._zarr_v3_name!r}"
647647
raise DataTypeValidationError(msg)
648648

649-
@overload # type: ignore[override]
649+
@overload
650650
def to_json(self, zarr_format: Literal[2]) -> DTypeConfig_V2[Literal[">i2", "<i2"], None]: ...
651651

652652
@overload
@@ -806,7 +806,7 @@ def _from_json_v3(cls, data: DTypeJSON) -> Self:
806806
msg = f"Invalid JSON representation of UInt16. Got {data!r}, expected the string {cls._zarr_v3_name!r}"
807807
raise DataTypeValidationError(msg)
808808

809-
@overload # type: ignore[override]
809+
@overload
810810
def to_json(self, zarr_format: Literal[2]) -> DTypeConfig_V2[Literal[">u2", "<u2"], None]: ...
811811

812812
@overload
@@ -987,7 +987,7 @@ def _from_json_v3(cls, data: DTypeJSON) -> Self:
987987
msg = f"Invalid JSON representation of {cls.__name__}. Got {data!r}, expected the string {cls._zarr_v3_name!r}"
988988
raise DataTypeValidationError(msg)
989989

990-
@overload # type: ignore[override]
990+
@overload
991991
def to_json(self, zarr_format: Literal[2]) -> DTypeConfig_V2[Literal[">i4", "<i4"], None]: ...
992992

993993
@overload
@@ -1150,7 +1150,7 @@ def _from_json_v3(cls, data: DTypeJSON) -> Self:
11501150
msg = f"Invalid JSON representation of {cls.__name__}. Got {data!r}, expected the string {cls._zarr_v3_name!r}"
11511151
raise DataTypeValidationError(msg)
11521152

1153-
@overload # type: ignore[override]
1153+
@overload
11541154
def to_json(self, zarr_format: Literal[2]) -> DTypeConfig_V2[Literal[">u4", "<u4"], None]: ...
11551155
@overload
11561156
def to_json(self, zarr_format: Literal[3]) -> Literal["uint32"]: ...
@@ -1306,7 +1306,7 @@ def _from_json_v3(cls, data: DTypeJSON) -> Self:
13061306
msg = f"Invalid JSON representation of {cls.__name__}. Got {data!r}, expected the string {cls._zarr_v3_name!r}"
13071307
raise DataTypeValidationError(msg)
13081308

1309-
@overload # type: ignore[override]
1309+
@overload
13101310
def to_json(self, zarr_format: Literal[2]) -> DTypeConfig_V2[Literal[">i8", "<i8"], None]: ...
13111311
@overload
13121312
def to_json(self, zarr_format: Literal[3]) -> Literal["int64"]: ...
@@ -1435,7 +1435,7 @@ def _from_json_v3(cls, data: DTypeJSON) -> Self:
14351435
msg = f"Invalid JSON representation of {cls.__name__}. Got {data!r}, expected the string {cls._zarr_v3_name!r}"
14361436
raise DataTypeValidationError(msg)
14371437

1438-
@overload # type: ignore[override]
1438+
@overload
14391439
def to_json(self, zarr_format: Literal[2]) -> DTypeConfig_V2[Literal[">u8", "<u8"], None]: ...
14401440
@overload
14411441
def to_json(self, zarr_format: Literal[3]) -> Literal["uint64"]: ...

src/zarr/core/dtype/npy/string.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def _check_json_v3(cls, data: DTypeJSON) -> TypeGuard[FixedLengthUTF32JSONV3]:
171171
and isinstance(data["configuration"]["length_bytes"], int)
172172
)
173173

174-
@overload # type: ignore[override]
174+
@overload
175175
def to_json(self, zarr_format: Literal[2]) -> DTypeConfig_V2[str, None]: ...
176176

177177
@overload
@@ -512,7 +512,7 @@ def _from_json_v3(cls, data: DTypeJSON) -> Self:
512512
msg = f"Invalid JSON representation of {cls.__name__}. Got {data!r}, expected {cls._zarr_v3_name}."
513513
raise DataTypeValidationError(msg)
514514

515-
@overload # type: ignore[override]
515+
@overload
516516
def to_json(
517517
self, zarr_format: Literal[2]
518518
) -> DTypeConfig_V2[Literal["|O"], Literal["vlen-utf8"]]: ...

src/zarr/core/dtype/npy/structured.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def _from_json_v3(cls, data: DTypeJSON) -> Self:
232232
msg = f"Invalid JSON representation of {cls.__name__}. Got {data!r}, expected a JSON object with the key {cls._zarr_v3_name!r}"
233233
raise DataTypeValidationError(msg)
234234

235-
@overload # type: ignore[override]
235+
@overload
236236
def to_json(self, zarr_format: Literal[2]) -> DTypeConfig_V2[StructuredName_V2, None]: ...
237237

238238
@overload

src/zarr/core/dtype/npy/time.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def to_native_dtype(self) -> BaseTimeDType_co:
198198
dtype_string = f"{self._numpy_name}[{self.scale_factor}{self.unit}]"
199199
return np.dtype(dtype_string).newbyteorder(endianness_to_numpy_str(self.endianness)) # type: ignore[return-value]
200200

201-
@overload # type: ignore[override]
201+
@overload
202202
def to_json(self, zarr_format: Literal[2]) -> DTypeConfig_V2[str, None]: ...
203203
@overload
204204
def to_json(self, zarr_format: Literal[3]) -> DateTime64JSONV3 | TimeDelta64JSONV3: ...

0 commit comments

Comments
 (0)