Skip to content

Align object reduction and state callback controls - #9716

Merged
youknowone merged 3 commits into
RustPython:mainfrom
youknowdot:fix/object-state-controls-20261104
Nov 6, 2026
Merged

youknowone merged 3 commits into
RustPython:mainfrom
youknowdot:fix/object-state-controls-20261104

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Summary

Align object reduction and state callback controls with Python 3.15 in one production Rust file (+186/-128).

  • Bind the reduction protocol through existing index conversion to a signed C int, preserving the original temporary argument through reducer dispatch and using CPython's range error.
  • Always perform dynamic __getstate__ lookup. Use the native default fast path only for the original implementation bound to the same receiver; retain instance overrides, foreign-bound methods, lookup errors and callback ownership.
  • Preserve original slot-name objects as state dictionary keys. Release temporary names and values before rechecking slot-list size, and avoid unchecked indexing if a callback/finalizer changed that list.
  • Propagate errors from newargs descriptors through the existing strict special-method lookup. Release returned outer tuples before validating their children, and preserve explicit argument/keyword cleanup on failures.
  • Capture the current class at the correct point after callbacks, helper lookup and empty-keyword destruction. Release class-level reducer temporaries before invoking the instance reducer, and keep top-level result/failure cleanup in source order.

Existing binding, lookup, dictionary and method primitives are reused. No per-function keyword parser, test, Lib or workflow edits are introduced.

Validation

Compared with pinned CPython object reduction/state. The 29-case reference oracle reproduced exactly. Independent source review and additional safe failure, copyreg, class-mutation, slot-finalizer and temporary-protocol probes passed. Ordinary classes/subclasses and legal class reassignment were used; no malformed native layouts or unsafe cycles were exercised.

These are CPython reference results and source review, not a RustPython runtime pass. Native RustPython execution, full workspace/C-API suites and separate cross-platform graphs remain unperformed; hosted CI is required.

Limits and integration

Generic nested tuple member destruction still differs from CPython's reverse order. This patch fixes the changed top-level owners but does not redesign generic tuple teardown or claim full nested-container finalizer parity.

Fresh relevant PR patches were checked and do not duplicate this group. Composing with #9715 requires resolving the object.rs import hunk by retaining both its PyAnyDict import and this patch's native-function/method-descriptor imports. The directory and reduction behavior hunks are separate; combined execution is not claimed. Preserve the independent ownership/type-name work in #8939/#8944/#9700 and nearby #8848 length-access changes.

AI-assisted implementation and independent review using OpenAI Codex; model version is not exposed.

Final validation: threaded host-env/VM/stdlib cargo check passed in 1m12s and all-targets Clippy in 3m03s. Diagnostics exactly match the 12 unchanged baseline warnings. Normal repository commit hooks passed; no suppressions or unrelated baseline edits.

@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • 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

Preserve signed protocol arguments, dynamic state dispatch, original slot keys, and newargs ownership through shared lookup and conversion paths.

Assisted-by: OpenAI Codex:model version not exposed
@youknowdot
youknowdot force-pushed the fix/object-state-controls-20261104 branch from b522122 to fad2db2 Compare November 6, 2026 13:20
codex added 2 commits November 6, 2026 22:42
Preserve callback ownership, release ordering, and retained argument owners.

Assisted-by: Codex:model-version-unavailable
Assisted-by: Codex:model-version-unavailable
@youknowone
youknowone marked this pull request as ready for review November 6, 2026 23:46
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-06T23:46:14.826637Z
We couldn’t complete this review. Comment @codex review to try again.
2e35ed3 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

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@youknowone
youknowone merged commit 6e606b3 into RustPython:main Nov 6, 2026
20 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.

3 participants