Skip to content

Commit a0bff9a

Browse files
committed
feat: expore public type aliases from zarr.types
1 parent bd23984 commit a0bff9a

File tree

23 files changed

+104
-23
lines changed

23 files changed

+104
-23
lines changed

changes/3886.feature.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Export public type aliases from ``zarr.types``, including ``JSON``, ``ZarrFormat``, ``ShapeLike``, ``CompressorLike``, ``FiltersLike``, ``Selection``, and other types used in the public API.

docs/api/zarr/types.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: types
3+
---
4+
5+
::: zarr.types

docs/contributing.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,19 @@ prek list
183183

184184
If you would like to skip the failing checks and push the code for further discussion, use the `--no-verify` option with `git commit`.
185185

186+
### Public and private API
187+
188+
Zarr follows standard Python conventions for distinguishing public from private API:
189+
190+
- **Public modules** are top-level or one level deep: `zarr`, `zarr.dtype`, `zarr.types`, `zarr.codecs`, `zarr.storage`, etc. Users should only need to import from these modules.
191+
- **Private modules** use a leading underscore or are within `zarr.core` (e.g. `zarr.core.dtype.npy.common`, `zarr.core._info`). These are implementation details and may change without notice.
192+
- **`__all__`** declares the public API of a module. Every public module should define `__all__`. If a name is not in `__all__`, it is not part of the public API.
193+
- **Type aliases** used across the codebase (e.g. `JSON`, `ZarrFormat`, `ShapeLike`) are re-exported from [`zarr.types`][zarr.types]. External users and tests should import from `zarr.types`. Internal code may import from the defining module (e.g. `zarr.core.common`).
194+
- **Extension points** (custom codecs, data types) should be fully usable by importing only from public modules. If a user needs to reach into `zarr.core.*` to implement an extension, that is a gap in the public API.
195+
- **Entry points** (e.g. `zarr.codecs`, `zarr.data_type`) are part of the public plugin interface and should be documented in the [extending guide](user-guide/extending.md).
196+
197+
When adding new functionality, consider whether it belongs in the public API. If so, export it from the appropriate top-level module and add it to `__all__`. If it is an internal helper, place it in a private module or use a leading underscore.
198+
186199
### Test coverage
187200

188201
> **Note:** Test coverage for Zarr-Python 3 is currently not at 100%. This is a known issue and help is welcome to bring test coverage back to 100%. See issue #2613 for more details.

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ nav:
4949
- api/zarr/registry.md
5050
- api/zarr/storage.md
5151
- api/zarr/experimental.md
52+
- api/zarr/types.md
5253
- ABC:
5354
- api/zarr/abc/index.md
5455
- api/zarr/abc/buffer.md

src/zarr/types.py

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,73 @@
11
from typing import Any
22

3-
from zarr.core.array import Array, AsyncArray
3+
from zarr.core.array import (
4+
Array,
5+
AsyncArray,
6+
CompressorLike,
7+
CompressorsLike,
8+
FiltersLike,
9+
SerializerLike,
10+
ShardsLike,
11+
)
12+
from zarr.core.array_spec import ArrayConfigLike
13+
from zarr.core.buffer import NDArrayLikeOrScalar
14+
from zarr.core.chunk_key_encodings import ChunkKeyEncodingLike
15+
from zarr.core.common import (
16+
JSON,
17+
AccessModeLiteral,
18+
BytesLike,
19+
ChunksLike,
20+
DimensionNamesLike,
21+
MemoryOrder,
22+
NodeType,
23+
ShapeLike,
24+
ZarrFormat,
25+
)
26+
from zarr.core.dtype import ZDTypeLike
27+
from zarr.core.indexing import (
28+
BasicSelection,
29+
CoordinateSelection,
30+
Fields,
31+
MaskSelection,
32+
OrthogonalSelection,
33+
Selection,
34+
)
435
from zarr.core.metadata.v2 import ArrayV2Metadata
536
from zarr.core.metadata.v3 import ArrayV3Metadata
637

38+
__all__ = [
39+
"JSON",
40+
"AccessModeLiteral",
41+
"AnyArray",
42+
"AnyAsyncArray",
43+
"ArrayConfigLike",
44+
"ArrayV2",
45+
"ArrayV3",
46+
"AsyncArrayV2",
47+
"AsyncArrayV3",
48+
"BasicSelection",
49+
"BytesLike",
50+
"ChunkKeyEncodingLike",
51+
"ChunksLike",
52+
"CompressorLike",
53+
"CompressorsLike",
54+
"CoordinateSelection",
55+
"DimensionNamesLike",
56+
"Fields",
57+
"FiltersLike",
58+
"MaskSelection",
59+
"MemoryOrder",
60+
"NDArrayLikeOrScalar",
61+
"NodeType",
62+
"OrthogonalSelection",
63+
"Selection",
64+
"SerializerLike",
65+
"ShapeLike",
66+
"ShardsLike",
67+
"ZDTypeLike",
68+
"ZarrFormat",
69+
]
70+
771
type AnyAsyncArray = AsyncArray[Any]
872
"""A Zarr format 2 or 3 `AsyncArray`"""
973

tests/package_with_entrypoint/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from typing import Any, ClassVar, Literal, Self
1818

1919
from zarr.core.array_spec import ArraySpec
20-
from zarr.core.common import ZarrFormat
20+
from zarr.types import ZarrFormat
2121

2222

2323
class TestEntrypointCodec(ArrayBytesCodec):

tests/test_api.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
from pathlib import Path
1616

1717
from zarr.abc.store import Store
18-
from zarr.core.common import JSON, MemoryOrder, ZarrFormat
19-
from zarr.types import AnyArray
18+
from zarr.types import JSON, AnyArray, MemoryOrder, ZarrFormat
2019

2120
import contextlib
2221
from typing import Literal

tests/test_array.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
from zarr.core.buffer import NDArrayLike, NDArrayLikeOrScalar, default_buffer_prototype
4949
from zarr.core.chunk_grids import _auto_partition
5050
from zarr.core.chunk_key_encodings import ChunkKeyEncodingParams
51-
from zarr.core.common import JSON, ZarrFormat, ceildiv
51+
from zarr.core.common import ceildiv
5252
from zarr.core.dtype import (
5353
DateTime64,
5454
Float32,
@@ -76,7 +76,7 @@
7676
)
7777
from zarr.storage import LocalStore, MemoryStore, StorePath
7878
from zarr.storage._logging import LoggingStore
79-
from zarr.types import AnyArray, AnyAsyncArray
79+
from zarr.types import JSON, AnyArray, AnyAsyncArray, ZarrFormat
8080

8181
from .test_dtype.conftest import zdtype_examples
8282

tests/test_attributes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import zarr.core.attributes
99
import zarr.storage
1010
from tests.conftest import deep_nan_equal
11-
from zarr.core.common import ZarrFormat
11+
from zarr.types import ZarrFormat
1212

1313
if TYPE_CHECKING:
1414
from zarr.types import AnyArray

tests/test_cli/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import zarr
77
from zarr.abc.store import Store
8-
from zarr.core.common import ZarrFormat
8+
from zarr.types import ZarrFormat
99

1010

1111
def create_nested_zarr(

0 commit comments

Comments
 (0)