GeezerVison is showing github.com — Update `test_itertools.py` to 3.13.7 by ShaharNaveh · Pull Request #6122 · RustPython/RustPython
Conversation
ShaharNaveh
commented
Sep 2, 2025
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary by CodeRabbit
- New Features
- itertools.count now supports named arguments for start and step, in addition to positional usage, improving call flexibility without changing behavior.
- itertools.batched adds a strict parameter (default: false). When enabled, it raises a ValueError ("batched(): incomplete batch") if the final batch is shorter than n; when disabled, it preserves the previous behavior by returning a shorter final batch.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
Sep 2, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
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 support
vm/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 mode
vm/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
Loading
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
Suggested reviewers
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 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.
❤️ Share
🪧 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
@coderabbitai in a new review comment at the desired location with your query.
- PR comments: Tag
@coderabbitai in 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 ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
- Add
@coderabbitai summary to generate the high-level summary at a specific location in the PR description.
- Add
@coderabbitai anywhere 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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
vm/src/stdlib/itertools.rs (1)
2016-2025: Strict-mode enforcement is correct; minor preallocation nit.
Logic correctly raises ValueError("batched(): incomplete batch") only when the final batch is short and non-empty. Consider preallocating to reduce reallocs:
- let mut result: Vec<PyObjectRef> = Vec::new();
+ let mut result: Vec<PyObjectRef> = Vec::with_capacity(n);
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📥 Commits
Reviewing files that changed from the base of the PR and between fa91df6 and 3d8cac3.
⛔ Files ignored due to path filters (1)
Lib/test/test_itertools.py is excluded by !Lib/**
📒 Files selected for processing (1)
vm/src/stdlib/itertools.rs (5 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style (cargo fmt to format)
Always run clippy to lint code (cargo clippy) before completing tasks. Fix any warnings or lints that are introduced by your changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass, pymodule, pyfunction, etc.) when implementing Python functionality in Rust
Files:
vm/src/stdlib/itertools.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: Check the WASM package and demo
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Ensure compilation on various targets
- GitHub Check: Run rust tests (macos-latest)
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
- GitHub Check: Run rust tests (windows-latest)
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Run rust tests (ubuntu-latest)
- GitHub Check: Run tests under miri
- GitHub Check: Check Rust code with rustfmt and clippy
- GitHub Check: Run snippets and cpython tests on wasm-wasi
🔇 Additional comments (5)
vm/src/stdlib/itertools.rs (5)
241-246: Accepting keyword args for count(start, step) looks correct and matches CPython 3.13.
This relaxes the arg kind to allow both positional and keyword; good alignment with CPython.
Please confirm pickling behavior for non-default step: CPython includes step in __reduce__ when step != 1. Our current __reduce__ only returns (cls, (cur,)), which might drop step on unpickle. If tests for that exist in 3.13.7, ensure they pass.
1945-1949: Adding strict flag storage in batched is appropriate.
Per-instance AtomicCell matches the pattern used elsewhere here.
1957-1959: Keyword-only strict with default False matches CPython signature.
Keyword-only via #[pyarg(named, ...)] is the right choice for batched(iterable, n, /, *, strict=False).
1966-1971: Argument destructuring updated to include strict — good.
1982-1987: Persisting strict in the instance — good.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|