Skip to content

Align OrderedDict views and sync pprint with CPython 3.15 - #9134

Merged
youknowone merged 2 commits into
RustPython:mainfrom
youknowdot:split/ordered-dict-view-bases
Oct 15, 2026
Merged

youknowone merged 2 commits into
RustPython:mainfrom
youknowdot:split/ordered-dict-view-bases

Conversation

@youknowdot

@youknowdot youknowdot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Make OrderedDict keys, values, and items views actual subclasses of the corresponding dict view types, with one shared base payload and owner reference.
  • Inherit common descriptors and set operations while retaining OrderedDict's forward/reverse iteration order.
  • Match CPython 3.15.0 view repr: snapshot through the actual iterator before invoking element reprs, use the concrete view type name, and preserve recursion/exception handling.

Update Lib/pprint.py and Lib/test/test_pprint.py together with their native prerequisite, using actual scripts/update_lib migrate imports from CPython 3.15.0 (d220409a13b77de7a6c30abe16ea90db01528edc). Both files are byte-for-byte identical to the pinned final git blobs. This adds final pprint mapping-view, frozendict, template and expansion support without hand-edited library changes.

Validation

Validated on base 3ab5c0c2f207e335972cd16b776b9b522ffe7e0f:

  • Narrow threaded release build.
  • Strict VM/stdlib all-target Clippy (-D warnings) and normal commit hooks.
  • 24 bounded dict/OrderedDict canonical and targeted view checks.
  • 33 unchanged CPython 3.15.0 pprint methods against the exact-final library pair included in this PR.
  • 6 ordered-view regression cases, including the mega PR's failing pprint sorting and recursion cases.

Each runtime case ran in a fresh process with a 30-second timeout and 1-GiB address-space limit; no skips or expected failures. This is targeted validation, not the full test suite or a GC lifetime proof.

The latest main (92e20da822ef511853d207da9ff2338e7c3a57f5) merges cleanly; its partial/vectorcall, tzdb, marshal and update_lib updates were not included in the local validation build.

One existing type-registration discrepancy remains: public __module__ is correctly builtins, while the internal type dictionary contains a module entry (now _collections, previously builtins; CPython has no such entry). This patch does not redesign module registration.

Summary by CodeRabbit

  • Behavior Changes
    • Ordered dictionary key, value, and item views now follow the corresponding standard dictionary view behavior. Custom comparisons and set operations are no longer available on these views; iteration and reverse iteration remain supported.
    • Dictionary view representations now use the view’s runtime class name and show ... for recursive representations.

Use dict view base payloads and inherited descriptors while preserving ordered iteration. Snapshot actual view iterators before rendering element reprs.

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

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e5396ec2-604d-4a5c-b061-89a36f2f9e25
📥 Commits

Reviewing files that changed from the base of the PR and between edb5ac4 and e15a230.

⛔ Files ignored due to path filters: 2
  • Lib/pprint.py is excluded by !Lib/**
  • Lib/test/test_pprint.py is excluded by !Lib/**
📒 Files selected for processing: 3
  • crates/vm/src/builtins/dict.rs
  • crates/vm/src/stdlib/_collections/ordered_dict.rs
  • crates/vm/src/stdlib/mod.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

OrderedDict views now wrap and inherit from the corresponding PyDict view types while retaining ordered iteration. Dict-view representations and native item-view XOR detection were also updated.

Changes: Dictionary views

Layer / File(s) Summary
Base dictionary view behavior
crates/vm/src/builtins/dict.rs
Dict-view representations now snapshot items through the view iterator and use the runtime class’s slot name. Recursive representations return "...". Native item-view XOR detection recognizes only PyDictItems.
OrderedDict view wrappers
crates/vm/src/stdlib/_collections/ordered_dict.rs, crates/vm/src/stdlib/mod.rs
OrderedDict key, value, and item views now wrap and inherit from the corresponding PyDict views. They retain ordered iteration and reverse iteration. Custom view implementations were removed, and the PyOrderedDictItems re-export was removed.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Suggested reviewers: youknowone

Merge Risk: ⚪ Minimal · up to e15a2

OrderedDict views now subclass the standard dict views while keeping insertion order, and their representations match CPython 3.15. No concrete defects were identified, so the change appears ready to merge after the normal test runs.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 31.58% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 3 files. 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 clearly and concisely describes the two main changes: aligning OrderedDict views and synchronizing pprint behavior with CPython 3.15.
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.
  • Fix all pre-merge checks 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.

Import the related library update using scripts/update_lib migrate from d220409a13b77de7a6c30abe16ea90db01528edc, preserving exact final source bytes.

Assisted-by: OpenAI Codex:model version unavailable
@youknowdot youknowdot changed the title Align OrderedDict view inheritance and repr with CPython Align OrderedDict views and sync pprint with CPython 3.15 Oct 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

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

:4: SyntaxWarning: invalid decimal literal
:7: SyntaxWarning: "\z" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\z"? A raw string is also an option.
:10: SyntaxWarning: "\400" is an invalid octal escape sequence. Such sequences will not work in the future. Did you mean "\400"? A raw string is also an option.
:4: SyntaxWarning: invalid decimal literal
:7: SyntaxWarning: "\z" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\z"? A raw string is also an option.
:10: SyntaxWarning: "\400" is an invalid octal escape sequence. Such sequences will not work in the future. Did you mean "\400"? A raw string is also an option.
:4: SyntaxWarning: invalid decimal literal
:7: SyntaxWarning: "\z" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\z"? A raw string is also an option.
:10: SyntaxWarning: "\400" is an invalid octal escape sequence. Such sequences will not work in the future. Did you mean "\400"? A raw string is also an option.
[x] lib: cpython/Lib/pprint.py
[x] test: cpython/Lib/test/test_pprint.py

dependencies:

  • pprint

dependent tests: (96 tests)

  • pprint: test_htmlparser test_pprint test_ssl test_sys_setprofile test_unittest
    • pdb: test_pdb
    • pickle: test_annotationlib test_argparse test_array test_ast test_asyncio test_bool test_builtin test_bytes test_bz2 test_codecs test_collections test_concurrent_futures test_configparser test_coroutines test_csv test_ctypes test_decimal test_defaultdict test_deque test_descr test_dict test_dictviews test_email test_enum test_enumerate test_exceptions test_fractions test_functools test_generators test_genericalias test_http_cookies test_importlib test_inspect test_io test_ipaddress test_iter test_itertools test_list test_logging test_lzma test_memoryio test_memoryview test_minidom test_opcache test_operator test_ordered_dict test_os test_pathlib test_pickle test_picklebuffer test_pickletools test_platform test_plistlib test_positional_only_arg test_posix test_random test_range test_re test_set test_shelve test_slice test_socket test_statistics test_str test_string test_structseq test_super test_time test_trace test_tuple test_turtle test_type_aliases test_type_params test_types test_typing test_unittest test_uuid test_xml_dom_minicompat test_xml_etree test_xpickle test_zipfile test_zlib test_zoneinfo
      • logging: test_asyncio test_concurrent_futures test_hashlib test_pkgutil test_support test_urllib2net
      • tracemalloc: test_tracemalloc

Legend:

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

@youknowone
youknowone marked this pull request as ready for review October 15, 2026 06:56
@youknowone
youknowone enabled auto-merge (squash) October 15, 2026 06:56
@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-15T07:06:02.547396Z e15a230 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: e15a230514

ℹ️ 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 Lib/test/test_pprint.py
pp = pprint.PrettyPrinter()

for icky in self.a, self.b, self.d, (self.d, self.d):
for icky in self.a, self.b, self.d, (self.d, self.d), self.e, self.v, self.m, self.dv:

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 forbidden test-body changes

This upstream sync expands the existing test_knotted inputs and, elsewhere in the file, adds or changes test logic, assertions, and data; the repository policy permits test-file edits only for adding or removing expected-failure markers. Revert these test-body changes or express unsupported behavior with the allowed markers so the commit complies with the test policy.

AGENTS.md reference: AGENTS.md:L273-L279

Useful? React with 👍 / 👎.

@youknowone
youknowone merged commit 8a9d66c into RustPython:main Oct 15, 2026
30 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.

2 participants