Skip to content

Commit ba8df41

Browse files
authored
Merge pull request RustPython#3775 from joohongpark/fix-test_dict_mixed_keys_items
fix test_dictviews::test_dict_mixed_keys_items
2 parents cea5a6e + 79eae0d commit ba8df41

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

Lib/test/test_dictviews.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ def test_dict_items(self):
6060
e["a"] = "def"
6161
self.assertNotEqual(d.items(), e.items())
6262

63-
# TODO: RUSTPYTHON
64-
@unittest.expectedFailure
6563
def test_dict_mixed_keys_items(self):
6664
d = {(1, 1): 11, (2, 2): 22}
6765
e = {1: 1, 2: 2}

vm/src/builtins/dict.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::{
1515
function::{
1616
ArgIterable, FuncArgs, KwArgs, OptionalArg, PyArithmeticValue::*, PyComparisonValue,
1717
},
18+
iter::PyExactSizeIterator,
1819
protocol::{PyIterIter, PyIterReturn, PyMappingMethods, PySequenceMethods},
1920
recursion::ReprGuard,
2021
types::{
@@ -998,23 +999,30 @@ trait ViewSetOps: DictView {
998999
) -> PyResult<PyComparisonValue> {
9991000
match_class!(match other {
10001001
ref dictview @ Self => {
1001-
PyDict::inner_cmp(
1002+
return PyDict::inner_cmp(
10021003
zelf.dict(),
10031004
dictview.dict(),
10041005
op,
10051006
!zelf.class().is(vm.ctx.types.dict_keys_type),
10061007
vm,
1007-
)
1008+
);
10081009
}
10091010
ref _set @ PySet => {
10101011
let inner = Self::to_set(zelf.to_owned(), vm)?;
10111012
let zelf_set = PySet { inner }.into_pyobject(vm);
1012-
PySet::cmp(zelf_set.downcast_ref().unwrap(), other, op, vm)
1013+
return PySet::cmp(zelf_set.downcast_ref().unwrap(), other, op, vm);
10131014
}
1015+
ref _dictitems @ PyDictItems => {}
1016+
ref _dictkeys @ PyDictKeys => {}
10141017
_ => {
1015-
Ok(NotImplemented)
1018+
return Ok(NotImplemented);
10161019
}
1017-
})
1020+
});
1021+
let lhs: Vec<PyObjectRef> = zelf.as_object().to_owned().try_into_value(vm)?;
1022+
let rhs: Vec<PyObjectRef> = other.to_owned().try_into_value(vm)?;
1023+
lhs.iter()
1024+
.richcompare(rhs.iter(), op, vm)
1025+
.map(PyComparisonValue::Implemented)
10181026
}
10191027

10201028
#[pymethod]

0 commit comments

Comments
 (0)