Skip to content

Support pickling slot wrapper descriptors - #9037

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix-wrapper-descriptor-pickle
Oct 10, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix-wrapper-descriptor-pickle

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Support pickling slot wrapper descriptors such as object.__str__, matching CPython 3.14. Reduce each descriptor to getattr on its defining class.

Extracted from #8954. Adds direct reduction and one roundtrip assertion to the existing pickle snippet. Canonical expected-failure markers remain because those tests also expose unrelated staticmethod-descriptor failures.

Validation:

  • CPython 3.14.7 passes the snippet. The pre-fix RustPython baseline raises TypeError for wrapper descriptor reduction.
  • Normal pre-commit hooks and VM Clippy pass.
  • Patched native runtime and aggregate tests await CI; local runtime linking is blocked by available disk space.

AI-assisted implementation, tests, and review with OpenAI Codex. Kept as a draft for CI and maintainer review.

Extract wrapper descriptor reduction from RustPython#8954 for Python 3.14. Reduce to getattr on the defining class and cover direct reduction plus one roundtrip in the existing pickle snippet. Preserve canonical expected failures for unrelated staticmethod descriptor behavior.

Assisted-by: OpenAI Codex:model identifier unavailable
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ccac2943-6ae0-46b7-b629-c9a1d3e9dfe9

📥 Commits

Reviewing files that changed from the base of the PR and between 3af5f8a and f1a9eca.


📒 Files selected for processing (2)
  • crates/vm/src/builtins/descriptor.rs
  • extra_tests/snippets/stdlib_pickle.py

 _____________________________
< Lint today, shine tomorrow. >
 -----------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Comment @coderabbitai help to get the list of available commands.

@youknowone
youknowone marked this pull request as ready for review October 10, 2026 10:32
@youknowone
youknowone merged commit e3374c8 into RustPython:main Oct 10, 2026
21 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T10:38:36.600081Z f1a9eca Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f1a9ecada7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

)]
impl Py<PyWrapper> {
#[pymethod]
fn __reduce__(&self, vm: &VirtualMachine) -> PyResult {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add the required AI-assistance trailer

This commit explicitly states that its implementation and review were AI-assisted, but its message has no Assisted-by: AGENT_NAME:MODEL_VERSION trailer; the repository requires that exact trailer format for every AI-assisted contribution, so rewrite the commit message before merging.

AGENTS.md reference: AGENTS.md:L22-L23

Useful? React with 👍 / 👎.

Comment on lines +14 to +15
assert object.__str__.__reduce__() == (getattr, (object, "__str__"))
assert _pickle.loads(_pickle.dumps(object.__str__)) is object.__str__

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove the forbidden test assertions

These lines add new assertion logic to a test file, but the repository rules prohibit test assertion/logic edits and state that the only acceptable test-file changes are adding or removing expected-failure markers; remove these assertions or obtain an explicit policy exception before merging.

AGENTS.md reference: AGENTS.md:L275-L279

Useful? React with 👍 / 👎.

impl Py<PyWrapper> {
#[pymethod]
fn __reduce__(&self, vm: &VirtualMachine) -> PyResult {
let getattr = vm.builtins.get_attr("getattr", vm)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Resolve getattr from the current frame's builtins

When __reduce__ is called from an exec/eval frame whose custom __builtins__ mapping overrides or omits getattr, CPython uses that frame-local value (or raises AttributeError), whereas this lookup always reads the interpreter's global builtins module. VirtualMachine::eval_get_builtin already implements the required _PyEval_GetBuiltin semantics, so using the module directly here returns or serializes the wrong callable in custom-builtins contexts.

Useful? React with 👍 / 👎.

youknowdot added a commit to youknowdot/RustPython that referenced this pull request Oct 11, 2026
Follow up on RustPython#9037 by using the existing frame-aware builtin lookup.

Assisted-by: OpenAI Codex:model identifier unavailable
youknowdot added a commit to youknowdot/RustPython that referenced this pull request Oct 11, 2026
Follow up on RustPython#9037 by using the existing frame-aware builtin lookup.

Assisted-by: OpenAI Codex:model identifier unavailable
youknowdot added a commit to youknowdot/RustPython that referenced this pull request Oct 11, 2026
Follow up on RustPython#9037 by using the existing frame-aware builtin lookup.

Assisted-by: OpenAI Codex:model identifier unavailable
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