Skip to content

Conversation

ShaharNaveh
Copy link
Collaborator

@ShaharNaveh ShaharNaveh commented Sep 4, 2025

Summary by CodeRabbit

  • Chores
    • Added deprecation warnings when pickling/copying/deep-copying itertools iterators (scheduled removal in Python 3.14). Also added a spell-check dictionary entry for "Itertool" and fixed a trailing newline.
  • Refactor
    • Unified emission of these deprecation warnings across many itertools iterator types; normal iteration behavior unchanged.

Copy link
Contributor

coderabbitai bot commented Sep 4, 2025

Walkthrough

Adds a pickle deprecation helper and emits DeprecationWarning from many itertools __reduce__ methods by wiring pickle_deprecation(vm) into their flows and updating signatures to accept &VirtualMachine; reduction return values remain unchanged.

Changes

Cohort / File(s) Summary
itertools reductions update
vm/src/stdlib/itertools.rs
Adds pickle_deprecation(vm) and use warnings; injects calls to emit a DeprecationWarning ("removed in Python 3.14") into many __reduce__ implementations and updates those signatures to accept &VirtualMachine where needed; reduction return values preserved.
spell dictionary tweak
.cspell.dict/cpython.txt
Adds Itertool entry and ensures file ends with a trailing newline.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant Iter as itertools::__reduce__
  participant Dep as pickle_deprecation(vm)
  participant Warn as warnings.warn

  Caller->>Iter: call __reduce__(..., vm)
  activate Iter
  Iter->>Dep: pickle_deprecation(vm)
  activate Dep
  Dep->>Warn: emit DeprecationWarning ("removed in Python 3.14")
  deactivate Dep
  Iter-->>Caller: return original reduction tuple
  deactivate Iter

  note right of Iter: Applied across multiple itertools classes
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

I hop through iterators, soft and spry,
A tiny warn before the pickle flies.
By 3.14 this trail will fade,
I nibble code and leave a shade.
Still the tuples come back the same—
A rabbit's nod in development game. 🐇


📜 Recent 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 4e6b9a5 and f563048.

📒 Files selected for processing (1)
  • .cspell.dict/cpython.txt (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .cspell.dict/cpython.txt
⏰ 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: Run snippets and cpython tests (macos-latest)
  • GitHub Check: Run snippets and cpython tests on wasm-wasi
  • GitHub Check: Check Rust code with rustfmt and clippy
  • GitHub Check: Run tests under miri
  • GitHub Check: Run snippets and cpython tests (windows-latest)
  • GitHub Check: Run rust tests (windows-latest)
  • GitHub Check: Check the WASM package and demo
  • GitHub Check: Run rust tests (ubuntu-latest)
  • GitHub Check: Run snippets and cpython tests (ubuntu-latest)
  • GitHub Check: Run rust tests (macos-latest)
  • GitHub Check: Ensure compilation on various targets
✨ 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
vm/src/stdlib/itertools.rs (1)

1142-1181: Convert iterator structs to Python objects before tuple construction
In vm/src/stdlib/itertools.rs, the PyItertoolsChain and PyItertoolsAccumulate instances must be converted via .into_pyobject(vm) before passing to vm.new_tuple, as they don’t implement ToPyObject/IntoPyTuple directly and will fail to compile otherwise.

--- a/vm/src/stdlib/itertools.rs
@@ 1158
-               let chain = PyItertoolsChain {
+               let chain = PyItertoolsChain {
                   source: PyRwLock::new(Some(chain_args.to_pyobject(vm).get_iter(vm).unwrap())),
                   active: PyRwLock::new(None),
-               };
+               }.into_pyobject(vm);
@@ 1163
-                   let acc = Self {
+                   let acc = Self {
                       iterable: PyIter::new(chain),
                       bin_op,
                       initial: None,
                       acc_value: PyRwLock::new(None),
-                   };
+                   }.into_pyobject(vm);
🧹 Nitpick comments (2)
vm/src/stdlib/itertools.rs (2)

32-39: Fix deprecation message grammar and consider higher stacklevel.

  • "Itertool" → "itertools"; "in a Python 3.14" → "in Python 3.14".
  • Use stacklevel=2 (or 3) so the warning points closer to the user site that triggered pickling.

Apply:

 fn pickle_deprecation(vm: &VirtualMachine) -> PyResult<()> {
     warnings::warn(
         vm.ctx.exceptions.deprecation_warning,
-        "Itertool pickle/copy/deepcopy support will be removed in a Python 3.14.".to_owned(),
-        1,
+        "itertools pickle/copy/deepcopy support is deprecated and will be removed in Python 3.14.".to_owned(),
+        2,
         vm,
     )
 }

Also please confirm the exact deprecation version text matches CPython’s plan for 3.14.


964-975: Confirm whether reading state via AtomicCell::take() is intentional.

take() resets cur and next to 0 as a side-effect during reduction. If pickling should be read-only, consider load() instead and pass state explicitly.

Example adjustment if needed:

-            let cur = zelf.cur.take();
-            let next = zelf.next.take();
+            let cur = zelf.cur.load();
+            let next = zelf.next.load();
📜 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 85ca280 and 4e6b9a5.

⛔ 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 (16 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
🧬 Code graph analysis (1)
vm/src/stdlib/itertools.rs (3)
vm/src/stdlib/warnings.rs (2)
  • warn (5-18)
  • warn (39-48)
vm/src/warn.rs (1)
  • warn (76-87)
vm/src/builtins/function.rs (1)
  • __reduce__ (788-796)
⏰ 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). (10)
  • GitHub Check: Run snippets and cpython tests (windows-latest)
  • GitHub Check: Run rust tests (macos-latest)
  • GitHub Check: Run snippets and cpython tests (macos-latest)
  • GitHub Check: Run snippets and cpython tests (ubuntu-latest)
  • GitHub Check: Check the WASM package and demo
  • GitHub Check: Run snippets and cpython tests on wasm-wasi
  • GitHub Check: Run rust tests (ubuntu-latest)
  • GitHub Check: Run rust tests (windows-latest)
  • GitHub Check: Check Rust code with rustfmt and clippy
  • GitHub Check: Ensure compilation on various targets
🔇 Additional comments (13)
vm/src/stdlib/itertools.rs (13)

22-22: Import of warnings module looks fine.

Consistent with using the stdlib warnings shim for emitting Python-level warnings.


84-99: Deprecation call placement is correct.

Calling the helper before constructing the reduction tuple and using ? matches the method’s PyResult signature.


217-223: Consistent handling for non-PyResult return.

Using let _ = pickle_deprecation(vm); is appropriate here since the method doesn’t return PyResult.


288-291: LGTM for count.reduce.

Deprecation hooked without altering existing reduction payload.


420-427: LGTM for repeat.reduce.

Helper used with ? as the method returns PyResult.


490-499: LGTM for starmap.reduce.

Consistent pattern; no change to reduction data.


559-569: LGTM for takewhile.reduce.

Deprecation integrated; state value unchanged.


647-657: LGTM for dropwhile.reduce.

Deprecation integrated; state value unchanged.


1061-1070: LGTM for filterfalse.reduce.

Pattern matches other reducers; no behavior change beyond the warning.


1407-1431: LGTM for product.reduce.

Deprecation added; payload unchanged.


1517-1543: LGTM for combinations.reduce.

Warning insertion is correct; state handling unaffected.


1759-1765: LGTM for permutations.reduce.

Consistent with other reducers; no additional state serialized.


1873-1885: LGTM for zip_longest.reduce.

Helper called with ?; reduction tuple intact.

Copy link
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 please check the comment about cspell

fn pickle_deprecation(vm: &VirtualMachine) -> PyResult<()> {
warnings::warn(
vm.ctx.exceptions.deprecation_warning,
"Itertool pickle/copy/deepcopy support will be removed in a Python 3.14.".to_owned(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Itertool pickle/copy/deepcopy support will be removed in a Python 3.14.".to_owned(),
"Itertools pickle/copy/deepcopy support will be removed in a Python 3.14.".to_owned(),

Otherwise adding itertool to cspell dictionary will fix the CI failure

Copy link
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@youknowone youknowone merged commit da71b92 into RustPython:main Sep 7, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants