-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rule proposal: require explicit strict=
argument for itertools.batched
#498
Comments
What sort of bugs do you see this catching? At work we have a helper function equivalent to |
That's understandable! However, I don't think it is obvious to an inexperienced user or someone who hasn't read the documentation that not all batches in Off the top of my head, some examples of the uniformity of batch sizes being important include
IMO, asking users to use |
I'm a little confused of the total value of this rule too. I get the goal, but feel the loose nature of this lint will lead to it possible being noisy ... or am I misunderstanding things here? I feel if people need these assertions you make their unit tests should enforce those and hilight the non equal batch sizes becoming a problem. I'd need more wins here I feel. Is the main goal to ensure people to always set |
I do see both sides of the argument, but I think on balance there's enough benefits here to create a rule. However, I think it should be opt-in like |
Yes, essentially. I had in mind |
I was unaware we wanted this to be optional / opt in. Based on that, I'd accept it the PR as the next B9XX rule. FWIW, I am sure 99% of our opt in rules do not get used by our users tho. |
As of Python 3.13,
itertools.batched
has astrict
parameter that defaults toFalse
. By default, the batches might not be of the same size, which may cause subtle bugs. Whenstrict=True
, it raisesValueError
if the final batch is not the same size as the rest.This seems analogous to the existing rule
B905
which requires an explicitstrict=
parameter forzip
. Hence, I think it makes sense if there is a similar rule foritertools.batched
.I volunteer to implement the rule, if accepted!
The text was updated successfully, but these errors were encountered: