Skip to content

Commit 6095557

Browse files
committed
Fix dict+set tests
1 parent 2f03db9 commit 6095557

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

vm/src/obj/objdict.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,20 @@ impl PyDict {
157157
item: bool,
158158
vm: &VirtualMachine,
159159
) -> PyResult<PyComparisonValue> {
160+
if op == PyComparisonOp::Ne {
161+
return Self::inner_cmp(zelf, other, PyComparisonOp::Eq, item, vm)
162+
.map(|x| x.map(|eq| !eq));
163+
}
160164
if !op.eval_ord(zelf.len().cmp(&other.len())) {
161165
return Ok(Implemented(false));
162166
}
163-
let (zelf, other) = if zelf.len() < other.len() {
167+
let (superset, subset) = if zelf.len() < other.len() {
164168
(other, zelf)
165169
} else {
166170
(zelf, other)
167171
};
168-
for (k, v1) in other {
169-
match zelf.get_item_option(k, vm)? {
172+
for (k, v1) in subset {
173+
match superset.get_item_option(k, vm)? {
170174
Some(v2) => {
171175
if v1.is(&v2) {
172176
continue;
@@ -421,11 +425,8 @@ impl Comparable for PyDict {
421425
vm: &VirtualMachine,
422426
) -> PyResult<PyComparisonValue> {
423427
op.eq_only(|| {
424-
if let Ok(other) = other.downcast::<PyDict>() {
425-
Self::inner_cmp(zelf, other, PyComparisonOp::Eq, true, vm)
426-
} else {
427-
Ok(PyComparisonValue::NotImplemented)
428-
}
428+
let other = class_or_notimplemented!(Self, other);
429+
Self::inner_cmp(zelf, other, PyComparisonOp::Eq, true, vm)
429430
})
430431
}
431432
}

vm/src/obj/objset.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ impl PySetInner {
112112
op: PyComparisonOp,
113113
vm: &VirtualMachine,
114114
) -> PyResult<bool> {
115+
if op == PyComparisonOp::Ne {
116+
return self.compare(other, PyComparisonOp::Eq, vm).map(|eq| !eq);
117+
}
115118
if !op.eval_ord(self.len().cmp(&other.len())) {
116119
return Ok(false);
117120
}

0 commit comments

Comments
 (0)