Skip to content

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

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

Closed
tjkuson opened this issue Nov 16, 2024 · 5 comments · Fixed by #14408
Closed

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

tjkuson opened this issue Nov 16, 2024 · 5 comments · Fixed by #14408
Labels
rule Implementing or modifying a lint rule

Comments

@tjkuson
Copy link
Contributor

tjkuson commented Nov 16, 2024

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

@AlexWaygood AlexWaygood added the rule Implementing or modifying a lint rule label Nov 16, 2024
@InSyncWithFoo
Copy link
Contributor

I'll take this on.

@MichaReiser
Copy link
Member

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.

@tjkuson
Copy link
Contributor Author

tjkuson commented Dec 8, 2024

Merged as B911 upstream.

@MichaReiser
Copy link
Member

Great. @InSyncWithFoo do you want to update your PR and recode the rule to B911?

@InSyncWithFoo
Copy link
Contributor

Done, and thanks @tjkuson for the heads-up.

MichaReiser added a commit that referenced this issue Dec 10, 2024
…B911`) (#14408)

## Summary

Resolves #14387.

## Test Plan

`cargo nextest run` and `cargo insta test`.

---------

Co-authored-by: Micha Reiser <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants