⚡ Sangsakala Proxy 🏠 Home
Skip to content

Align object reduction and state callback controls - #9716

Draft
youknowdot wants to merge 1 commit into
RustPython:mainfrom
youknowdot:fix/object-state-controls-20261104
Draft

youknowdot wants to merge 1 commit 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.

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
@coderabbitai

coderabbitai Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • 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

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.

1 participant