Skip to content

Accept JSON encoder keyword arguments and normalize initial indentation - #9459

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix/json-indent-315-20261029
Oct 29, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix/json-indent-315-20261029

Conversation

@youknowdot

@youknowdot youknowdot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Accept the nine CPython keyword names in _json.make_encoder and obj / _current_indent_level in encoder calls, while preserving positional arguments.
  • Treat a negative initial indentation level as zero before entering recursive encoding, matching the empty prefix produced by CPython's negative string repetition.
  • Retire the sole local marker in the whole test_json/test_speedups.py through scripts/update_lib from the pinned CPython source.

CPython basis

Pinned source: d220409a13b77de7a6c30abe16ea90db01528edc.

The integer digit-limit work in #8087 is independent and is not duplicated here. Generic argument-binding error wording and inherited constructor validation precedence are not changed.

Verification

Scoped check and strict Clippy passed. A bounded CLI build timed out during code generation; the same command then completed successfully using its cached dependencies. The resulting protected binary passed:

  • Ten ordinary canonical test_speedups methods in both RustPython and pinned CPython, with zero failures, errors, skips or expected failures.
  • Twenty finite records matched CPython byte-for-byte, covering nested output, keyword/mixed construction and calls, negative/zero/positive initial levels, rejected duplicate/missing/unknown arguments, and __index__ callbacks.
  • The complete test module was refreshed using scripts/update_lib migrate; its bytes match the pinned canonical source used by validation.

Validation used base 95bf39a54b67df408db9da53cfc546e711c93895. The branch was subsequently fast-forwarded to bcaa07a7d843c2a027bfb5773b56f1b8601ca33b, whose two deque-related files do not overlap this change. The tested native source is byte-identical after that integration and normal commit hooks passed. No new runtime pass is claimed for that final base; current-head CI remains required.

The two explicit GC/mutation tests in the module were excluded from local execution. Full workspace/C-API suites, concurrency/GC/stress tests and extreme allocation cases were not run. Generic binder error wording and inherited constructor validation precedence are outside this patch.

AI assistance: OpenAI Codex (model version unavailable).

Summary by CodeRabbit

  • Bug Fixes
    • JSON encoding now treats negative indentation levels as zero, preventing them from producing invalid indentation behavior. Nonnegative indentation settings continue to work as before, so existing formatting choices remain unchanged. This update affects the output only when a negative indentation level is provided; it does not change the available JSON encoding options or the values used for other settings.

Match CPython encoder_new/encoder_call keyword names and negative initial indentation prefix behavior. Refresh the complete speedups test module through update_lib after scoped canonical and oracle validation.

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

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between bcaa07a and 3ec2193.

Files ignored due to path filters: 1
  • Lib/test/test_json/test_speedups.py is excluded by !Lib/**
Files selected for processing: 1
  • crates/stdlib/src/json.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Walkthrough

The JSON encoder constructor and call method now receive argument structs instead of nested tuples. The call method also clamps negative indent values to zero before encoding.

Changes: JSON Encoder

Layer / File(s) Summary
Use structs for encoder arguments
crates/stdlib/src/json.rs
The constructor and call method use argument structs. The call method clamps negative indent values to zero before encoding.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: youknowone

Merge Risk: Minimal · up to 3ec21

The encoder changes support the expected keyword arguments while preserving positional calls. No actionable merge-blocking issue was identified; current-head CI should pass before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names two changes that the changeset contains: accepting JSON encoder keyword arguments (EncoderArgs and EncoderCallArgs structs replace tuples, with the CPython keyword names) and normalizi…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names two changes that the changeset contains: accepting JSON encoder keyword arguments (EncoderArgs and EncoderCallArgs structs replace tuples, with the CPython keyword names) and normalizing the initial indentation (negative indent levels are clamped to zero). The title is specific and matches the primary change in crates/stdlib/src/json.rs. It is slightly long at 71 characters, but it is clear and not vague.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 1 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

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.

@github-actions

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[x] lib: cpython/Lib/json
[ ] test: cpython/Lib/test/test_json (TODO: 1)

dependencies:

  • json

dependent tests: (21 tests)

  • json: test_embed test_interpreters test_json test_logging test_plistlib test_profiling test_pydoc test_pyrepl test_remote_pdb test_subprocess test_sysconfig test_tomllib test_tools test_traceback test_zoneinfo
    • importlib.metadata: test_importlib
    • multiprocessing.resource_tracker: test_concurrent_futures
    • pdb: test_pdb
    • profiling: test_profiling
      • cProfile: test_free_threading test_pstats

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

@youknowone
youknowone marked this pull request as ready for review October 29, 2026 13:06
@youknowone
youknowone enabled auto-merge (squash) October 29, 2026 13:06
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 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 ⚠️ Failed 2026-10-29T13:08:28.128472Z
We couldn’t complete this review. Comment @codex review to try again.
3ec2193 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.

@codspeed

codspeed Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing youknowdot:fix/json-indent-315-20261029 (3ec2193) with main (bcaa07a)

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@youknowone
youknowone merged commit d24ca41 into RustPython:main Oct 29, 2026
22 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