-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix set in-place operators with self argument #6661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 |
ShaharNaveh
left a comment
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.
lgtm
|
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.