GeezerVison is showing github.com — Align Union construction and callback controls by youknowdot · Pull Request #9714 · RustPython/RustPython
Conversation
youknowdot
commented
Nov 4, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary
- Build Union arguments through one streaming builder, preserving checked typing construction separately from unchecked type/GenericAlias operators. Subscription uses exact-tuple unpacking; substitution validates directly without invoking user
__or__ or __ror__.
- Preserve creation-time hashable/unhashable partitions for equality and hashing. Freeze stored set entries without repeating hash or collision callbacks, and preserve identity shortcuts and containment comparison direction.
- Preserve callback errors and ownership: only the initial hash failure classifies an argument as unhashable; subsequent hash failures use the shared contextual formatter while comparison exceptions remain unchanged. Keep original inputs alive and release failed-builder lists in reverse order.
Validation
- Independent source/ownership review and 19 pinned CPython 3.15 oracle groups passed, covering callback order, exception identity, temporary lifetimes, partition equality and checked-entry-point differences.
- Final threaded
cargo check passed for host_env, VM and stdlib. Threaded all-targets Clippy passed with exactly the same 12 existing diagnostics as the baseline and no new warning.
- Rustfmt,
git diff --check, and normal commit hooks passed.
Native RustPython execution is not available under the required safety guard; no native runtime or full test-suite pass is claimed. The separate non-threaded/WASM graph was not built under the current disk limit.
Integration notes
The shared dictionary hash-error formatter extraction is intentionally identical to the helper in #9693 rather than another implementation. Its set operation changes still require reconciling add/add_known_hash: preserve #9693's hash-only contextualization, keep raw collision errors unchanged, and delegate to one raw insertion helper. The formatter also overlaps #9700's Unicode-preserving key_hash change: retain the extracted WTF-8 helper and #9700's other qualified-name improvements. Source composition was inspected; the combined branches have not been compiled.
Union/GenericAlias representation formatting and unrelated set-operation behavior remain outside this change. Repository tests, standard-library files and workflows are unchanged.
Summary by CodeRabbit
- Bug Fixes
- Union creation and
| operations now consistently flatten nested unions, remove duplicate members, and handle unhashable members.
- Empty unions now raise an error, while a union containing only one unique member returns that member directly.
- Hashing errors for dictionary keys now include context about the key and container while preserving non-
TypeError exceptions.
- Converting a set to a frozen set no longer rehashes or compares its stored keys.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
Nov 4, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

Walkthrough
-
Union construction and operators now use a shared builder to normalize and deduplicate members. Set helpers and dictionary hash-error contextualization support this path. Union equality and hashing use member partitions recorded at creation.
Changes: Union behavior
| Layer / File(s) |
Summary |
Set and hash support crates/vm/src/builtins/dict.rs, crates/vm/src/builtins/set.rs |
Dictionary hash failures can be contextualized with key and container details. Set operations expose helpers for known-hash membership and insertion, and freezing copies stored entries without rehashing or comparing keys. |
Union construction and normalization crates/vm/src/builtins/union.rs |
UnionBuilder normalizes None, flattens nested unions, and deduplicates hashable and unhashable members. Union operators, class subscription, construction, and generic substitution use the builder. |
Union equality and hashing crates/vm/src/builtins/union.rs |
Equality compares creation-time hashable and unhashable partitions. Hashing uses the stored hashable frozenset and reports the count of creation-time unhashable members. |
Estimated code review effort: 4 (Complex) | ~45 minutes
Change: Bug fix
Sequence Diagram(s)
sequenceDiagram
participant PyUnion.__or__
participant UnionBuilder
participant PySet
PyUnion.__or__->>UnionBuilder: Add operands with type checking
UnionBuilder->>PySet: Deduplicate hashable members using set semantics
UnionBuilder-->>PyUnion.__or__: Return normalized union or lone member
Loading
Possibly related PRs
Suggested reviewers: youknowone, shaharnaveh, jorge-polanco-roque
Merge Risk: Minimal · up to 4ee5c
-
No actionable merge-blocking issue is established by the supplied evidence. Merge after normal checks; native execution and the non-threaded build remain unverified.
Pre-merge checks: 4 · 1
-
Failed checks: 1 warning
| Check name |
Status |
Explanation |
Resolution |
| Docstring Coverage |
 |
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 checks: 4 passed
-
| Check name |
Status |
Explanation |
| Description Check |
 |
Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check |
 |
The title clearly describes the main changes: shared Union construction and callback/error control behavior. It is concise and specific. |
| Linked Issues check |
 |
Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check |
 |
Check skipped because no linked issues were found for this pull request. |
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 13 functions across 3 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches
-
Generate unit tests (beta)
-
- 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
-
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Codex Review Summary
This comment shows the latest Codex review activity on this pull request.
| Review |
Status |
Commit |
Review trigger |
| 📝 Code Review |
⚠️ Failed 2026-11-05T03:15:55.562285Z We couldn’t complete this review. Comment @codex review to try again. |
106f001 |
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Share checked and unchecked construction while preserving cached partitions, hash failures, and temporary argument ownership.
Assisted-by: OpenAI Codex:model version not exposed
auto-merge was automatically disabled
November 5, 2026 14:52 Head branch was pushed to by a user without write access
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|