⚡ Sangsakala Proxy 🏠 Home
Skip to content

Align JSON encoder callback state with Python 3.15 - #9671

Open
youknowdot wants to merge 1 commit into
RustPython:mainfrom
youknowdot:fix/json-callback-state-315
Open

youknowdot wants to merge 1 commit into
RustPython:mainfrom
youknowdot:fix/json-callback-state-315

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Summary

Align the native JSON encoder's callback-visible state with Python 3.15:

  • Retain and expose the caller's marker dictionary. Use native dictionary operations for subclasses, keep markers on failure, and propagate callback-induced deletion errors.
  • Iterate unsorted exact dictionaries live so callbacks can update subsequent values or entries.
  • Preserve the exact list returned by a dictionary subclass's items(), sort it using the shared list implementation, and validate pairs as they are consumed.
  • Convert encoder flags through the existing ArgIntoBool binding helper before constructor validation.

The change reuses the VM's mapping, list sorting, dictionary iteration and native dictionary helpers. It makes the existing native dictionary deletion helper available to the standard-library crate rather than duplicating its implementation.

Reference behavior is defined by CPython's encoder construction, default callback handling, and mapping iteration.

Validation

  • Formatting and whitespace checks pass.
  • Bounded Python 3.15 reference probes cover marker visibility and retention, reentrant calls, marker dictionary subclasses, callback-driven dictionary/list mutations, lazy pair validation, in-place tuple sorting, temporary-object lifetime and flag-conversion order.
  • cargo check --locked --offline -j1 -p rustpython-stdlib --features rustpython-stdlib/threading passed.
  • cargo clippy --locked --offline -j1 -p rustpython-vm -p rustpython-host_env -p rustpython-stdlib --features rustpython-stdlib/threading -- -D warnings passed.
  • Native RustPython runtime tests, full workspace/CAPI suites and cross-platform tests were not run. Reference probes establish target semantics, not runtime validation.
  • Production Rust files only; no tests or workflows changed.

AI assistance: OpenAI Codex assisted with source comparison, implementation and reference probes under maintainer direction.

Retain caller markers, preserve callback-visible iteration and error state, and reuse shared flag conversion and list sorting.

Assisted-by: OpenAI Codex:model version not exposed
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 19 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 0b081b0 and a2c208c.

Files selected for processing: 2
  • crates/stdlib/src/json.rs
  • crates/vm/src/builtins/dict.rs
  • 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

@youknowone
youknowone marked this pull request as ready for review November 4, 2026 12:52
@youknowone
youknowone enabled auto-merge (squash) November 4, 2026 12:52
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 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-11-04T13:05:49.515762Z a2c208c 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: a2c208c0d4

ℹ️ 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".

Comment thread crates/stdlib/src/json.rs
item_separator: PyStrRef,
#[pyarg(any)]
sort_keys: PyObjectRef,
sort_keys: ArgIntoBool,

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 Reject surplus keywords before coercing encoder flags

When all nine parameters are supplied together with an unexpected keyword, FuncArgs::bind_for() only prechecks the positional count and rejects leftover keywords after T::from_args(). These ArgIntoBool fields therefore invoke a flag's __bool__ before rejecting the invalid call. If that callback raises, its exception escapes instead of the TypeError returned before this commit and by the CPython reference; otherwise, its side effects still run unexpectedly. Preflight the surplus-keyword/total-argument check before converting the flags, while preserving the intended conversion order for valid calls.

Useful? React with 👍 / 👎.

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