Update `test_itertools.py` to 3.13.7 by ShaharNaveh · Pull Request #6122 · RustPython/RustPython
Walkthrough
Updates in itertools: count() now accepts start and step as keyword or positional arguments. batched() gains a new strict boolean parameter (default false). Internally, PyItertoolsBatched stores a strict flag and next() enforces raising ValueError("batched(): incomplete batch") when strict is true and the final batch is short.
Changes
| Cohort / File(s) | Summary |
|---|---|
Count args keyword supportvm/src/stdlib/itertools.rs |
CountNewArgs.start and CountNewArgs.step decorators changed from positional, optional to any, optional, allowing named arguments without altering behavior. |
Batched strict modevm/src/stdlib/itertools.rs |
Added strict arg to BatchedNewArgs (default false). PyItertoolsBatched now has strict: AtomicCell<bool>. Constructor updated to accept/init strict. next() computes batch length and, when strict is true and length != n, raises ValueError("batched(): incomplete batch"). |
Sequence Diagram(s)
sequenceDiagram
autonumber
participant Py as Python Code
participant B as batched(iterable, n, strict)
participant I as PyItertoolsBatched
participant It as Underlying Iterator
Py->>B: construct with iterable, n, strict?
B->>I: py_new(iterable_ref, n, strict)
Note right of I: strict stored in AtomicCell<bool>
loop next()
Py->>I: __next__()
I->>It: collect up to n items
alt collected count == 0
I-->>Py: StopIteration
else collected count in (1..n)
alt strict == true and count != n
I-->>Py: raise ValueError("batched(): incomplete batch")
else
I-->>Py: return batch (len == count)
end
end
end
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
Suggested reviewers
- youknowone
Poem
Thump-thump, I batch with careful bite,
Count hops now named—how polite!
Strict mode nips short stacks in twain,
“Incomplete!” I cry on the data plain.
Carrot in paw, I test each chunk—
Perfect piles, no half-filled bunk. 🥕
✨ Finishing Touches
- 📝 Generate Docstrings
🧪 Generate unit tests
- Create PR with unit tests
- Post copyable unit tests in a comment
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. - PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
CodeRabbit Commands (Invoked using PR/Issue comments)
Type @coderabbitai help to get the list of available commands.
Other keywords and placeholders
- Add
@coderabbitai ignoreor@coderabbit ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
Status, Documentation and Community
- Visit our Status Page to check the current availability of CodeRabbit.
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.