batched-without-explicit-strict (B911)
Added in 0.10.0 · Related issues · View source
Derived from the flake8-bugbear linter.
What it does
Checks for itertools.batched calls without an explicit strict parameter.
Why is this bad?
By default, if the length of the iterable is not divisible by
the second argument to itertools.batched, the last batch
will be shorter than the rest.
In Python 3.13, a strict parameter was added which allows controlling if the batches must be of uniform length.
Pass strict=True to raise a ValueError if the batches are of non-uniform length.
Otherwise, pass strict=False to make the intention explicit.
Example
Use instead if the batches must be of uniform length:
Or if the batches can be of non-uniform length:
Known deviations
Unlike the upstream B911, this rule will not report infinite iterators
(e.g., itertools.cycle(...)).