| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
WalkthroughUpdates 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
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
Poem✨ Finishing Touches
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 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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
Status, Documentation and Community
|
Sorry, something went wrong.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)vm/src/stdlib/itertools.rs (1)📜 Review details2016-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);
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration.
📥 CommitsReviewing files that changed from the base of the PR and between fa91df6 and 3d8cac3.
⛔ Files ignored due to path filters (1)📄 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 (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.
| Back | FazBrowse Home | New Git URL |
Summary by CodeRabbit