GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Fix some set operation to compare self with args by kth496 · Pull Request #3912 · RustPython/RustPython Conversation
|
|
It is up to you, but you don't need to put everything in single PR. You can submit splat small PRs for each functions. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| #[pymethod(magic)] | ||
| fn iand(zelf: PyRef<Self>, set: AnySet, vm: &VirtualMachine) -> PyResult<PyRef<Self>> { | ||
| fn iand(zelf: PyRef<Self>, set: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyRef<Self>> { | ||
| if zelf.get_id() == set.get_id() { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| if zelf.get_id() == set.get_id() { | |
| if zelf.is(&set) { |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if zelf.get_id() == set.get_id() { | ||
| return Ok(zelf); | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
intersection_update also needs to have a check like this. As iand and intersection_update share the same PySetInner::intersection_update, we can do better 😊
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@youknowone I think these operations are related closely. @Snowapril Thanks for your advice! I'll try to improve it! 👍 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
2da603f to
b378f64
Compare
b378f64 to
2930c84
Compare
|
@youknowone @Snowapril I tried to remove duplicated codes. But there are some different constraints between inplace operation methods. (Please See NOTE below) NOTE:
Same issue on |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
About your concern, I think your approach is reasonable enough.
Maybe there can be more room to do better, but current versions looks good enough to handle them in proper cost.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| zelf.inner | ||
| .intersection_update(std::iter::once(set.into_iterable(vm)?), vm)?; | ||
| fn iand(zelf: PyRef<Self>, set: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyRef<Self>> { | ||
| if !set.class().is(vm.ctx.types.set_type) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
how about frozenset? if frozenset is allowed, maybe AnySet check?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
yeah, frozen sets are allowed here. Similarly for isub and ixor.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if let Some(iterable) = arguments.first() { | ||
| if zelf.is(iterable) { | ||
| return Ok(()); | ||
| } | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think this check is not only adaptable for len() == 1 case but also do for every argument.
For example, how about s = set(['a']); s.intersection_update(s, s, s, s, s, s)?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| .intersection_update(std::iter::once(set.into_iterable(vm)?), vm)?; | ||
| fn iand(zelf: PyRef<Self>, set: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyRef<Self>> { | ||
| if !set.class().is(vm.ctx.types.set_type) { | ||
| return Err(vm.new_type_error("Type error".to_owned())); |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Should be "unsupported operand type(s) for +=: 'type1' and 'type2'", similarly for the rest of the type errors.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
2930c84 to
0312c8e
Compare
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
set intersection_update, difference_update, symmetric_difference_update should check self is equal to given arg
There was an error while loading. Please reload this page.