Skip to content

Commit 2ef62cf

Browse files
Apply ruff/refurb rule FURB140
FURB140 Use `itertools.starmap` instead of the generator
1 parent 4bd1175 commit 2ef62cf

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

src/zarr/abc/store.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from abc import ABC, abstractmethod
44
from asyncio import gather
55
from typing import TYPE_CHECKING, NamedTuple, Protocol, runtime_checkable
6+
from itertools import starmap
67

78
if TYPE_CHECKING:
89
from collections.abc import AsyncGenerator, Iterable
@@ -282,7 +283,7 @@ async def _set_many(self, values: Iterable[tuple[str, Buffer]]) -> None:
282283
"""
283284
Insert multiple (key, value) pairs into storage.
284285
"""
285-
await gather(*(self.set(key, value) for key, value in values))
286+
await gather(*starmap(self.set, values))
286287
return
287288

288289
@property

src/zarr/core/array.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
from zarr.registry import get_pipeline_class
8181
from zarr.storage import StoreLike, make_store_path
8282
from zarr.storage.common import StorePath, ensure_no_existing_node
83+
from itertools import starmap
8384

8485
if TYPE_CHECKING:
8586
from collections.abc import Iterable, Iterator, Sequence
@@ -818,7 +819,7 @@ def cdata_shape(self) -> ChunkCoords:
818819
Tuple[int]
819820
The shape of the chunk grid for this array.
820821
"""
821-
return tuple(ceildiv(s, c) for s, c in zip(self.shape, self.chunks, strict=False))
822+
return tuple(starmap(ceildiv, zip(self.shape, self.chunks, strict=False)))
822823

823824
@property
824825
def nchunks(self) -> int:
@@ -1397,7 +1398,7 @@ def cdata_shape(self) -> ChunkCoords:
13971398
"""
13981399
The shape of the chunk grid for this array.
13991400
"""
1400-
return tuple(ceildiv(s, c) for s, c in zip(self.shape, self.chunks, strict=False))
1401+
return tuple(starmap(ceildiv, zip(self.shape, self.chunks, strict=False)))
14011402

14021403
@property
14031404
def nchunks(self) -> int:

src/zarr/core/chunk_grids.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,6 @@ def all_chunk_coords(self, array_shape: ChunkCoords) -> Iterator[ChunkCoords]:
188188
def get_nchunks(self, array_shape: ChunkCoords) -> int:
189189
return reduce(
190190
operator.mul,
191-
(ceildiv(s, c) for s, c in zip(array_shape, self.chunk_shape, strict=True)),
191+
itertools.starmap(ceildiv, zip(array_shape, self.chunk_shape, strict=True)),
192192
1,
193193
)

src/zarr/core/common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import numpy as np
1818

1919
from zarr.core.strings import _STRING_DTYPE
20+
from itertools import starmap
2021

2122
if TYPE_CHECKING:
2223
from collections.abc import Awaitable, Callable, Iterator
@@ -52,7 +53,7 @@ async def concurrent_map(
5253
items: Iterable[T], func: Callable[..., Awaitable[V]], limit: int | None = None
5354
) -> list[V]:
5455
if limit is None:
55-
return await asyncio.gather(*[func(*item) for item in items])
56+
return await asyncio.gather(*list(starmap(func, items)))
5657

5758
else:
5859
sem = asyncio.Semaphore(limit)

0 commit comments

Comments
 (0)