diff --git a/vm/src/builtins/dict.rs b/vm/src/builtins/dict.rs index ea31954251..73b73fab12 100644 --- a/vm/src/builtins/dict.rs +++ b/vm/src/builtins/dict.rs @@ -746,34 +746,6 @@ macro_rules! dict_view { } } - impl Comparable for $name { - fn cmp( - zelf: &PyObjectView, - other: &PyObject, - op: PyComparisonOp, - vm: &VirtualMachine, - ) -> PyResult { - match_class!(match other { - ref dictview @ Self => { - PyDict::inner_cmp( - &zelf.dict, - &dictview.dict, - op, - !zelf.class().is(&vm.ctx.types.dict_keys_type), - vm, - ) - } - ref _set @ PySet => { - // TODO: Implement comparison for set - Ok(NotImplemented) - } - _ => { - Ok(NotImplemented) - } - }) - } - } - impl PyValue for $name { fn class(vm: &VirtualMachine) -> &PyTypeRef { &vm.ctx.types.$class @@ -997,6 +969,35 @@ impl PyDictKeys { } impl Unconstructible for PyDictKeys {} +impl Comparable for PyDictKeys { + fn cmp( + zelf: &PyObjectView, + other: &PyObject, + op: PyComparisonOp, + vm: &VirtualMachine, + ) -> PyResult { + match_class!(match other { + ref dictview @ Self => { + PyDict::inner_cmp( + &zelf.dict, + &dictview.dict, + op, + !zelf.class().is(&vm.ctx.types.dict_keys_type), + vm, + ) + } + ref _set @ PySet => { + let inner = Self::to_set(zelf.to_owned(), vm)?; + let zelf_set = PySet { inner }.into_object(vm); + PySet::cmp(zelf_set.downcast_ref().unwrap(), other, op, vm) + } + _ => { + Ok(NotImplemented) + } + }) + } +} + impl ViewSetOps for PyDictItems {} #[pyimpl(with(DictView, Constructor, Comparable, Iterable, ViewSetOps))] impl PyDictItems { @@ -1022,7 +1023,36 @@ impl PyDictItems { } impl Unconstructible for PyDictItems {} -#[pyimpl(with(DictView, Constructor, Comparable, Iterable))] +impl Comparable for PyDictItems { + fn cmp( + zelf: &PyObjectView, + other: &PyObject, + op: PyComparisonOp, + vm: &VirtualMachine, + ) -> PyResult { + match_class!(match other { + ref dictview @ Self => { + PyDict::inner_cmp( + &zelf.dict, + &dictview.dict, + op, + !zelf.class().is(&vm.ctx.types.dict_keys_type), + vm, + ) + } + ref _set @ PySet => { + let inner = Self::to_set(zelf.to_owned(), vm)?; + let zelf_set = PySet { inner }.into_object(vm); + PySet::cmp(zelf_set.downcast_ref().unwrap(), other, op, vm) + } + _ => { + Ok(NotImplemented) + } + }) + } +} + +#[pyimpl(with(DictView, Constructor, Iterable))] impl PyDictValues {} impl Unconstructible for PyDictValues {}