Skip to content

_json: skip items() for empty dict subclasses - #9018

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix-json-empty-dict-subclasses
Oct 9, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix-json-empty-dict-subclasses

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Summary

Split the Python 3.14-compatible empty-dictionary encoder fix from #8954.

Check the native dictionary size before calling a subclass's items() method. Empty dictionary subclasses should encode as {} without invoking that method, matching CPython 3.14. Nonempty subclasses keep their custom items() behavior.

Extend the existing JSON snippet with empty-subclass cases at the root and inside a list, both sorting modes, and a nonempty-subclass control. No standard-library assertions change.

Validation

  • Reproduced the failure on main d0dfcb54 through the snippet runner: items() was called on an empty dictionary subclass.
  • The same snippet passes with this patch and on CPython 3.14.7.
  • All 14 selected canonical TestCDump, TestCDefault, and TestCIndent tests pass unchanged.
  • Release workspace test targets compile with --no-run, excluding WASM, venvlauncher, and C API; the separate C-API test target also compiles with --no-run.
  • Affected-crate Clippy and repository hooks pass.

Local runtime validation is limited to the focused snippet and canonical tests above. Broad Rust test targets were compile-checked, not executed.

Reference: CPython 3.14 dictionary encoder.

AI assistance

OpenAI Codex assisted with auditing the split, implementation, regression coverage, and validation. The runtime does not expose an exact model identifier.

Split the Python 3.14-compatible empty native dictionary fast path from RustPython#8954. Extend the existing JSON snippet with root, nested, sorting, and nonempty subclass regression coverage.

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

coderabbitai Bot commented Oct 9, 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: 63cf147b-41ea-4902-bc97-be654e85c58b

📥 Commits

Reviewing files that changed from the base of the PR and between d0dfcb5 and 05e06d0.


📒 Files selected for processing (2)
  • crates/stdlib/src/json.rs
  • extra_tests/snippets/stdlib_json.py

 _______________________________________
< Uniformly random comments incoming... >
 ---------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ 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 9, 2026 11:55
@youknowone
youknowone merged commit 48419bd into RustPython:main Oct 9, 2026
21 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 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-09T12:00:36.792092Z 05e06d0 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: 05e06d0e3a

ℹ️ 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
out: &mut Wtf8Buf,
vm: &VirtualMachine,
) -> PyResult<()> {
if dict.is_empty() {

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 mandatory Assisted-by trailer

The commit message explicitly states that OpenAI Codex assisted, but it has no Assisted-by: AGENT_NAME:MODEL_VERSION trailer. Because repository policy requires that trailer for every AI-assisted contribution, add it before this commit lands rather than relying on the prose AI-assistance section.

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

Useful? React with 👍 / 👎.

Comment thread crates/stdlib/src/json.rs
out: &mut Wtf8Buf,
vm: &VirtualMachine,
) -> PyResult<()> {
if dict.is_empty() {

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 Run the required test suites instead of compile-checking

The Validation section explicitly says the workspace and C-API targets were built with --no-run and that broad tests were not executed; it also only mentions a focused snippet run. For a change to interpreter behavior and extra_tests/snippets, compile checks do not satisfy the repository minimum of running workspace tests, C-API tests, and pytest -v, so run those suites before landing.

AGENTS.md reference: AGENTS.md:L35-L35

Useful? React with 👍 / 👎.



for sort_keys in (False, True):
assert json.dumps(EmptyDictWithItems(), sort_keys=sort_keys) == "{}"

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 Revert the unsupported test-file additions

Adding this loop and its assertions changes test logic in extra_tests/snippets/stdlib_json.py, but repository policy limits test-file modifications to removing an existing expected-failure/TODO when it passes or adding an expected-failure decorator. This regression block must therefore be removed from the change before landing.

AGENTS.md reference: AGENTS.md:L277-L279

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