Skip to content

Allow reflected fallback for in-place set operators - #9182

Open
1ndahous3 wants to merge 1 commit into
RustPython:mainfrom
1ndahous3:set_inplace_reflected
Open

1ndahous3 wants to merge 1 commit into
RustPython:mainfrom
1ndahous3:set_inplace_reflected

Conversation

@1ndahous3

@1ndahous3 1ndahous3 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Found while constructing a parser with Lark, where set |= OrderedSet raised TypeError instead of calling the reflected operator.

Summary

  • Return NotImplemented from set's |=, &=, -=, and ^= operators for unsupported right operands, allowing their reflected operators to run.

AI assistance

Written with Codex (GPT-6), reviewed by a human before submission.

Summary by CodeRabbit

  • Bug Fixes
    • In-place set union, intersection, subtraction, and symmetric difference now handle dictionary key views correctly, producing the expected set without changing the original set.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 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-17T22:54:53.312873Z 860ea6e PR opened
ℹ️ 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.

@coderabbitai

coderabbitai Bot commented Oct 17, 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: ed40ce41-a231-4514-ae4b-125c2d28689e
📥 Commits

Reviewing files that changed from the base of the PR and between 65bbaca and 860ea6e.

📒 Files selected for processing: 2
  • crates/vm/src/builtins/set.rs
  • extra_tests/snippets/builtin_set.py

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 four in-place set operators now return NotImplemented for right operands that are not sets or frozensets. Tests cover direct operator-method results and operations with a dictionary keys view.

Changes: Set In-Place Operator Dispatch

Layer / File(s) Summary
Operand checks and tests
crates/vm/src/builtins/set.rs, extra_tests/snippets/builtin_set.py
The subtraction, intersection, symmetric-difference, and union slots now check that the right operand is a set or frozenset. Tests expect each direct method to return NotImplemented for a dictionary keys view and check the corresponding operator result and source set.

Priority: ➖ Normal

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

Change: Bug fix

Suggested reviewers: youknowone

Merge Risk: ⚪ Minimal · up to 860ea

No merge-blocking issue is identified; the change is ready for normal checks.

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. Analyzed 1 functions across 2 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 describes the main change: unsupported right operands now allow reflected fallback for in-place set operators.
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.

@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: 860ea6e3c7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread extra_tests/snippets/builtin_set.py
}),
inplace_subtract: Some(|a, b, vm| {
if let Some(a) = a.downcast_ref::<PySet>() {
if let Some(a) = a.downcast_ref::<PySet>()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any case PySet but not PyAnySet?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the left operand needs to remain a PySet because these slots call mutating PySet::__i*__ methods. PyAnySet would also accept frozenset, which cannot be modified in place. Augmented assignment on a frozenset uses the regular binary operation and reassigns the result instead.

the right operand is only read, so accepting PyAnySet there is appropriate.

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