From d45ad9f27e3a324e177e7074b95320ac27a8e71a Mon Sep 17 00:00:00 2001 From: Chuck Daniels Date: Wed, 20 May 2026 14:54:32 -0400 Subject: [PATCH 1/3] Widen ChunksLike type alias Fixes #3869 --- src/zarr/core/array.py | 21 ++++++++------------- src/zarr/core/common.py | 2 +- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/zarr/core/array.py b/src/zarr/core/array.py index 8e8b9bd181..6e788532b7 100644 --- a/src/zarr/core/array.py +++ b/src/zarr/core/array.py @@ -4397,11 +4397,8 @@ async def init_array( chunk_key_encoding, zarr_format=zarr_format ) - if overwrite: - if store_path.store.supports_deletes: - await store_path.delete_dir() - else: - await ensure_no_existing_node(store_path, zarr_format=zarr_format) + if overwrite and store_path.store.supports_deletes: + await store_path.delete_dir() else: await ensure_no_existing_node(store_path, zarr_format=zarr_format) @@ -4417,14 +4414,12 @@ async def init_array( ) # Normalize the user's chunks into canonical ChunksTuple form - if chunks is None or chunks == "auto": - chunks_normalized = guess_chunks( - shape_parsed, - item_size, - max_bytes=SHARDED_INNER_CHUNK_MAX_BYTES if shards is not None else None, - ) - else: - chunks_normalized = normalize_chunks_nd(chunks, shape_parsed) + max_bytes = None if shards is None else SHARDED_INNER_CHUNK_MAX_BYTES + chunks_normalized = ( + guess_chunks(shape_parsed, item_size, max_bytes=max_bytes) + if chunks == "auto" + else normalize_chunks_nd(chunks, shape_parsed) + ) # Resolve chunks + shards into outer_chunks (grid metadata) and # inner (sub-chunk structure for ShardingCodec, None if no sharding) diff --git a/src/zarr/core/common.py b/src/zarr/core/common.py index 2279820d7a..eafffa1818 100644 --- a/src/zarr/core/common.py +++ b/src/zarr/core/common.py @@ -37,7 +37,7 @@ BytesLike = bytes | bytearray | memoryview ShapeLike = Iterable[int | np.integer[Any]] | int | np.integer[Any] -ChunksLike = ShapeLike | Sequence[Sequence[int]] | None +ChunksLike = ShapeLike | Iterable[Iterable[int]] # For backwards compatibility ChunkCoords = tuple[int, ...] ZarrFormat = Literal[2, 3] From 8aff3b02e1c14fa269dafd27e953665a603e725e Mon Sep 17 00:00:00 2001 From: Chuck Daniels Date: Wed, 20 May 2026 15:06:40 -0400 Subject: [PATCH 2/3] Add changelog file. --- changes/3990.misc.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changes/3990.misc.md diff --git a/changes/3990.misc.md b/changes/3990.misc.md new file mode 100644 index 0000000000..ff3fcf4cf2 --- /dev/null +++ b/changes/3990.misc.md @@ -0,0 +1,5 @@ +Widen `ChunksLike` type alias to use `Iterable` instead of `Sequence`, and also +remove `None` from the type union. This supports a broader range of types, +removing the necessity to "materialize" iterable values simply to satisfy type +annotations. It also allows use of `ChunksLike` in cases where `None` should +not be permitted. From b14924852fde89b77292c9c4d0f64ff4b6bbe382 Mon Sep 17 00:00:00 2001 From: Chuck Daniels Date: Wed, 20 May 2026 15:10:13 -0400 Subject: [PATCH 3/3] Prefer if/else statement to if/else expression --- src/zarr/core/array.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/zarr/core/array.py b/src/zarr/core/array.py index 6e788532b7..4e9bd6e12f 100644 --- a/src/zarr/core/array.py +++ b/src/zarr/core/array.py @@ -4414,12 +4414,12 @@ async def init_array( ) # Normalize the user's chunks into canonical ChunksTuple form - max_bytes = None if shards is None else SHARDED_INNER_CHUNK_MAX_BYTES - chunks_normalized = ( - guess_chunks(shape_parsed, item_size, max_bytes=max_bytes) - if chunks == "auto" - else normalize_chunks_nd(chunks, shape_parsed) - ) + + if chunks == "auto": + max_bytes = None if shards is None else SHARDED_INNER_CHUNK_MAX_BYTES + chunks_normalized = guess_chunks(shape_parsed, item_size, max_bytes=max_bytes) + else: + chunks_normalized = normalize_chunks_nd(chunks, shape_parsed) # Resolve chunks + shards into outer_chunks (grid metadata) and # inner (sub-chunk structure for ShardingCodec, None if no sharding)