Fix set in-place operators with self argument#6661
Fix set in-place operators with self argument#6661youknowone merged 1 commit intoRustPython:mainfrom
Conversation
📝 WalkthroughWalkthroughThe changes add self-reference checks to in-place set operations ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
|
Could you please rebase this branch on a fresh copy of |
|
Yes! I will rebase this afternoon when I get home. Thanks for the quick response. |
7a72db2 to
36bace4
Compare
youknowone
left a comment
There was a problem hiding this comment.
Thank you for contributing! The operation parts are looking perfect!
I left a suggestion to replace is_same_object to common RustPython internal mechanism. Please check it.
crates/vm/src/builtins/set.rs
Outdated
| fn is_same_object(&self, other: &PyObject) -> bool { | ||
| self.object.is(other) | ||
| } |
There was a problem hiding this comment.
We have a mechanism to do this.
is is not a method of PyObject, but an object ofAsObject. And PyObject is implementing AsObject through Borrow.
AnySet can do the same thing.
impl Borrow<PyObject> for AnySet {}
will enable AsObject for AnySet. Then set.is_same_object(zelf.as_object()) above can be simply written as set.is(zelf.as_object())
36bace4 to
dcbf4fb
Compare
|
Done. |
youknowone
left a comment
There was a problem hiding this comment.
Great! Thank you so much for contributing!
Co-authored-by: Hugh <[email protected]>
Fixes #3881
close #3912
close #4424
close #4708
When a set performs in-place operations with itself (
s &= s,s -= s,s ^= s), the operators now handle the self-reference case correctly:__iand__: no-op (intersection with self is unchanged)__isub__: clear (difference with self is empty)__ixor__: clear (symmetric difference with self is empty)Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.