astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
33.28k stars 1.11k forks source link

Rule proposal: require explicit `strict=` argument for `itertools.batched` #14387

Open tjkuson opened 2 weeks ago

tjkuson commented 2 weeks ago

As of Python 3.13, itertools.batched has a strict parameter that defaults to False. By default, the batches might not be of the same size, which may cause subtle bugs. Whenstrict=True, it raises ValueError if the final batch is not the same size as the rest.

This seems analogous to the existing rule B905 which requires an explicit strict= parameter for zip. Hence, I think it makes sense if there is a similar rule for itertools.batched.

I also created an issue flake8-bugbear which seems like a natural place for the rule given the similarity to B905.

Searched keywords: itertools.batched, itertools, batched

InSyncWithFoo commented 2 weeks ago

I'll take this on.

MichaReiser commented 1 week ago

Thanks for creating the upstream issue. Let's see what the outcome is upstream before adding this rule to avoid recoding in the near future.