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. diff --git a/src/zarr/core/array.py b/src/zarr/core/array.py index 8e8b9bd181..4e9bd6e12f 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,12 +4414,10 @@ 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, - ) + + 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) 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]