Skip to content

Align mapping boundaries with Python 3.15 final - #9128

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:split/mapping-boundaries-315
Oct 15, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:split/mapping-boundaries-315

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Summary

Extract related mapping-boundary compatibility changes from #8954, following CPython v3.15.0 final:

  • Accept exact dict/frozendict in one-argument str.maketrans, retain integer key objects, and raise the correct exception for unsupported inputs.
  • Protect exact mutable dictionaries behind mappingproxy from unknown reflected comparison callbacks by passing a copy, while preserving known mapping fast paths and custom mapping behavior.
  • Encode frozendict through the native JSON encoder, retaining exact-type fast paths and subclass .items() dispatch.

The only supporting change exposes PyOrderedDict within the VM crate for the exact-type comparison. No Lib/ or test files change. JSON array hooks and the pure-Python encoder remain separate work.

Validation

  • Fresh release build with threading/stdlib/stdio/importlib/host_env: passed.
  • Thirteen unchanged canonical CPython final methods, each in an isolated 30-second / 1-GiB process: passed, zero skips. Coverage includes maketrans/translate, dict/frozendict/custom mapping/OrderedDict comparisons and reflected mutation protection, plus native JSON nested mappings, skipkeys, ordering and sorting.
  • Strict VM/stdlib all-target Clippy with compiler/threading/host_env and -D warnings: passed.
  • Normal hooks and git diff --check: passed.

The initial extraction failed compilation because PyOrderedDict was private on main. Its two crate-local visibility/re-export prerequisites are included; no payload fields or OrderedDict implementation changed.

Canonical methods/helpers were copied unchanged into external bounded runners and verified against final d220409a13b77de7a6c30abe16ea90db01528edc. Full workspace/C-API suites, other platforms, concurrency/stress tests and broad JSON mutation semantics were not run locally; hosted CI remains required. Arbitrary-size integer-key preservation, integer-subclass identity and rejection of mapping subclasses in maketrans were source-reviewed, not covered by these selectors. JSON validation covers the native encoder only.

AI-assisted implementation and validation with OpenAI Codex.

Support frozen mappings in str.maketrans and native JSON encoding, preserve integer translation keys, and protect mappingproxy dictionaries from unknown reflected comparisons.

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

coderabbitai Bot commented Oct 14, 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: 7f493187-b2b7-471a-ba47-0b659cf98b70
📥 Commits

Reviewing files that changed from the base of the PR and between 0f93210 and e9f99cc.

📒 Files selected for processing: 5
  • crates/stdlib/src/json.rs
  • crates/vm/src/builtins/mappingproxy.rs
  • crates/vm/src/builtins/str.rs
  • crates/vm/src/stdlib/_collections/ordered_dict.rs
  • crates/vm/src/stdlib/mod.rs
+------------------------------------------+
| Fight fire with fire. Review AI with AI. |
+------------------------------------------+
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ 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 15, 2026 01:31
@youknowone
youknowone merged commit 3ab5c0c into RustPython:main Oct 15, 2026
30 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 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-15T01:40:44.364445Z e9f99cc 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: e9f99cc388

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

&& obj.class().is(vm.ctx.types.dict_type)
&& !(other.class().is(vm.ctx.types.dict_type)
|| other.class().is(vm.ctx.types.frozendict_type)
|| other.class().is(vm.ctx.types.mappingproxy_type)

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 Validate the mapping inside a whitelisted proxy

When other is an exact mappingproxy around an untrusted mapping, this exemption still exposes the protected dictionary: for MappingProxyType(victim) == MappingProxyType(Evil()), the outer slot skips the copy here, dict comparison returns NotImplemented, and the reflected proxy unwraps Evil, whose __eq__ then receives the original victim and can call clear() on it. Only exempt another proxy after verifying that its wrapped mapping is itself a known safe fast path (or remove this exemption), otherwise the reflected-callback protection is bypassable.

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