Skip to content

Preserve reflected multiplication for sequence subclasses - #9228

Open
1ndahous3 wants to merge 2 commits into
RustPython:mainfrom
1ndahous3:sequence_slot_inheritance
Open

1ndahous3 wants to merge 2 commits into
RustPython:mainfrom
1ndahous3:sequence_slot_inheritance

Conversation

@1ndahous3

@1ndahous3 1ndahous3 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Keep inherited sequence repetition out of numeric slots unless an override requires numeric dispatch. Subclasses now honor the right operand's __rmul__, including *=, without prematurely mutating the original container.
  • Preserve numeric dispatch inherited from mixins and when multiplication and in-place overrides are replaced or removed.

Follow-up to #8865 and #9049.

Performance

Release builds; median of five timing samples.

Windows 11 x64

Operation Main, ns/op Patched, ns/op Speedup
list subclass × 2 350 194 1.81×
str subclass × 2 320 182 1.75×

Debian 12 amd64

Operation Main, ns/op Patched, ns/op Speedup
list subclass × 2 309 163 1.89×
str subclass × 2 299 146 2.05×

AI assistance

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

Summary by CodeRabbit

  • Bug Fixes
    • Improved arithmetic operator behavior for inherited sequences. List multiplication and in-place addition or multiplication now handle reflected numeric operators and overrides more consistently, including when temporary overrides are removed.
    • Corrected inherited multiplication behavior so both left- and right-hand multiplication operations are preserved.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 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-20T06:02:36.617471Z 1073561 New commits
ℹ️ 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 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 79cb27ca-d67c-499d-9a00-ce64920146a8
📥 Commits

Reviewing files that changed from the base of the PR and between 1c2f024 and 1073561.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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: 600c08eb-caa3-401f-955e-7d408da02499
📥 Commits

Reviewing files that changed from the base of the PR and between c08375b and 1c2f024.

📒 Files selected for processing: 3
  • crates/vm/src/types/slot.rs
  • crates/vm/src/types/slot_defs.rs
  • extra_tests/snippets/operator_arithmetic.py

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

📝 Walkthrough

The changes update numeric slot handling for multiplication and in-place addition when inherited native sequence operations and reflected numeric methods are involved. New arithmetic tests cover these dispatch cases.

Changes: Operator Dispatch

Layer / File(s) Summary
Native sequence and numeric slot dispatch
crates/vm/src/types/slot.rs, crates/vm/src/types/slot_defs.rs
Numeric slot updates detect native sequence wrappers and use dedicated dispatch wrappers. NbMultiply now also copies an inherited right_multiply slot when the target slot is empty.
Reflected and in-place operator tests
extra_tests/snippets/operator_arithmetic.py
Tests cover reflected multiplication and addition with inherited list operations, including behavior after temporary __imul__ and __iadd__ overrides are deleted.

Priority: ⬇️ Low

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

Change: Bug fix

Suggested reviewers: youknowone, youknowdot

Merge Risk: ⚪ Minimal · up to 1c2f0

No actionable merge-blocking issue was identified; the change is mergeable after 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 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 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 main change: preserving reflected multiplication for sequence subclasses.
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.
✨ 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.

@codspeed

codspeed Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing 1ndahous3:sequence_slot_inheritance (1073561) with main (398dd70)

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. ↩

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.

1 participant