|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
3 | 3 | from abc import abstractmethod
|
4 |
| -from collections.abc import Mapping |
5 | 4 | from typing import (
|
6 | 5 | TYPE_CHECKING,
|
7 | 6 | Generic,
|
8 | 7 | Literal,
|
9 | 8 | Self,
|
10 |
| - TypedDict, |
11 | 9 | TypeVar,
|
12 | 10 | overload,
|
13 | 11 | )
|
14 | 12 |
|
15 |
| -from typing_extensions import ReadOnly, TypeIs |
16 |
| - |
17 | 13 | from zarr.abc.metadata import Metadata
|
18 | 14 | from zarr.core.buffer import Buffer, NDBuffer
|
19 |
| -from zarr.core.common import NamedConfig, ZarrFormat, concurrent_map |
| 15 | +from zarr.core.common import ( |
| 16 | + CodecJSON_V2, |
| 17 | + CodecJSON_V3, |
| 18 | + ZarrFormat, |
| 19 | + _check_codecjson_v2, |
| 20 | + concurrent_map, |
| 21 | +) |
20 | 22 | from zarr.core.config import config
|
21 | 23 |
|
22 | 24 | if TYPE_CHECKING:
|
|
46 | 48 | CodecOutput = TypeVar("CodecOutput", bound=NDBuffer | Buffer)
|
47 | 49 |
|
48 | 50 |
|
49 |
| -class CodecJSON_V2(TypedDict): |
50 |
| - """The JSON representation of a codec for Zarr V2""" |
51 |
| - |
52 |
| - id: ReadOnly[str] |
53 |
| - |
54 |
| - |
55 |
| -def _check_codecjson_v2(data: object) -> TypeIs[CodecJSON_V2]: |
56 |
| - """ |
57 |
| - A type narrowing function for the CodecJSON_V2 type |
58 |
| - """ |
59 |
| - return isinstance(data, Mapping) and "id" in data and isinstance(data["id"], str) |
60 |
| - |
61 |
| - |
62 |
| -CodecJSON_V3 = str | NamedConfig[str, Mapping[str, object]] |
63 |
| -"""The JSON representation of a codec for Zarr V3.""" |
64 |
| - |
65 |
| - |
66 |
| -def _check_codecjson_v3(data: object) -> TypeIs[CodecJSON_V3]: |
67 |
| - """ |
68 |
| - A type narrowing function for the CodecJSON_V3 type |
69 |
| - """ |
70 |
| - if isinstance(data, str): |
71 |
| - return True |
72 |
| - return ( |
73 |
| - isinstance(data, Mapping) |
74 |
| - and "name" in data |
75 |
| - and isinstance(data["name"], str) |
76 |
| - and isinstance(data.get("configuration", {}), Mapping) |
77 |
| - ) |
78 |
| - |
79 |
| - |
80 | 51 | # The widest type we will *accept* for a codec JSON
|
81 | 52 | # This covers v2 and v3
|
82 | 53 | CodecJSON = CodecJSON_V2 | CodecJSON_V3
|
|
0 commit comments