Repository navigation
fix: reject nonpositive batch sizes before consuming items - #62
Open
tongwentao wants to merge 1 commit into
Open
tongwentao wants to merge 1 commit into
tongwentao wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
batcher(range(3), 0)andbatcher(range(3), -1)currently return[[0, 1, 2]]: the batch length can never equal the requested size.abatcherhas the same problem with negative sizes, and accepts zero when an interval is supplied. With an unbounded source and no interval this can keep buffering without yielding.Validate the batch size before consuming or scheduling any source items, raising
ValueErrorfor zero and negative values.abatcher(batch_size=None, interval=...)keeps its interval-only behavior. The zero-size/no-interval async case now raisesValueErrorinstead of the existing assertion error. Both public docstrings and the changelog describe the requirement.Behavior and review notes
Because these APIs return generators, the validation takes effect when iteration begins, before the first source item is consumed. It does not make generator construction eager. Positive-size batching retains its existing yield behavior, and an async interval-only call remains valid with
batch_size=None; the intentional compatibility change is the exception type for invalid sizes.Validation on Python 3.13.5:
Other interpreter versions are left to CI. This change was prepared and validated with Codex.