Skip to content

Commit 05d0248

Browse files
committed
Fix rsub of PySet and PyFrozenSet
1 parent abf850a commit 05d0248

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

vm/src/builtins/set.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,20 @@ impl PySet {
604604
}
605605

606606
#[pymethod(magic)]
607-
fn rsub(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyArithmeticValue<Self>> {
608-
self.sub(other, vm)
607+
fn rsub(
608+
zelf: PyRef<Self>,
609+
other: PyObjectRef,
610+
vm: &VirtualMachine,
611+
) -> PyResult<PyArithmeticValue<Self>> {
612+
if let Ok(other) = AnySet::try_from_object(vm, other) {
613+
Ok(PyArithmeticValue::Implemented(Self {
614+
inner: other
615+
.as_inner()
616+
.difference(ArgIterable::try_from_object(vm, zelf.into())?, vm)?,
617+
}))
618+
} else {
619+
Ok(PyArithmeticValue::NotImplemented)
620+
}
609621
}
610622

611623
#[pymethod(name = "__rxor__")]
@@ -1003,8 +1015,20 @@ impl PyFrozenSet {
10031015
}
10041016

10051017
#[pymethod(magic)]
1006-
fn rsub(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyArithmeticValue<Self>> {
1007-
self.sub(other, vm)
1018+
fn rsub(
1019+
zelf: PyRef<Self>,
1020+
other: PyObjectRef,
1021+
vm: &VirtualMachine,
1022+
) -> PyResult<PyArithmeticValue<Self>> {
1023+
if let Ok(other) = AnySet::try_from_object(vm, other) {
1024+
Ok(PyArithmeticValue::Implemented(Self {
1025+
inner: other
1026+
.as_inner()
1027+
.difference(ArgIterable::try_from_object(vm, zelf.into())?, vm)?,
1028+
}))
1029+
} else {
1030+
Ok(PyArithmeticValue::NotImplemented)
1031+
}
10081032
}
10091033

10101034
#[pymethod(name = "__rxor__")]

0 commit comments

Comments
 (0)