mirror of
https://github.com/rommapp/romm.git
synced 2026-02-19 07:50:57 +01:00
Simplify annotations by using `__future__.annotations`, so there's no need to add typing using types as strings.
18 lines
493 B
Python
18 lines
493 B
Python
import sys
|
|
|
|
if sys.version_info >= (3, 12):
|
|
from itertools import batched # noqa: F401
|
|
else:
|
|
from collections.abc import Iterable, Iterator
|
|
from itertools import islice
|
|
from typing import TypeVar
|
|
|
|
T = TypeVar("T")
|
|
|
|
def batched(iterable: Iterable[T], n: int) -> Iterator[tuple[T, ...]]:
|
|
if n < 1:
|
|
raise ValueError("n must be at least one")
|
|
iterator = iter(iterable)
|
|
while batch := tuple(islice(iterator, n)):
|
|
yield batch
|