mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Add rand, ror, rsub operators in dict_keys
This commit is contained in:
2
Lib/test/test_dict.py
vendored
2
Lib/test/test_dict.py
vendored
@@ -642,8 +642,6 @@ class DictTest(unittest.TestCase):
|
||||
with self.assertRaises(RuntimeError):
|
||||
d3.items() > d2.items()
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_dictview_set_operations_on_keys(self):
|
||||
k1 = {1:1, 2:2}.keys()
|
||||
k2 = {1:1, 2:2, 3:3}.keys()
|
||||
|
||||
@@ -912,7 +912,39 @@ dict_view! {
|
||||
}
|
||||
|
||||
#[pyimpl(with(DictView, Comparable, Iterable))]
|
||||
impl PyDictKeys {}
|
||||
impl PyDictKeys {
|
||||
#[pymethod(name = "__rxor__")]
|
||||
#[pymethod(magic)]
|
||||
fn xor(zelf: PyRef<Self>, other: ArgIterable, vm: &VirtualMachine) -> PyResult<PySet> {
|
||||
let zelf = Self::to_set(zelf, vm)?;
|
||||
let inner = zelf.symmetric_difference(other, vm)?;
|
||||
Ok(PySet { inner })
|
||||
}
|
||||
|
||||
#[pymethod(name = "__rand__")]
|
||||
#[pymethod(magic)]
|
||||
fn and(zelf: PyRef<Self>, other: ArgIterable, vm: &VirtualMachine) -> PyResult<PySet> {
|
||||
let zelf = Self::to_set(zelf, vm)?;
|
||||
let inner = zelf.intersection(other, vm)?;
|
||||
Ok(PySet { inner })
|
||||
}
|
||||
|
||||
#[pymethod(name = "__ror__")]
|
||||
#[pymethod(magic)]
|
||||
fn or(zelf: PyRef<Self>, other: ArgIterable, vm: &VirtualMachine) -> PyResult<PySet> {
|
||||
let zelf = Self::to_set(zelf, vm)?;
|
||||
let inner = zelf.union(other, vm)?;
|
||||
Ok(PySet { inner })
|
||||
}
|
||||
|
||||
#[pymethod(name = "__rsub__")]
|
||||
#[pymethod(magic)]
|
||||
fn sub(zelf: PyRef<Self>, other: ArgIterable, vm: &VirtualMachine) -> PyResult<PySet> {
|
||||
let zelf = Self::to_set(zelf, vm)?;
|
||||
let inner = zelf.difference(other, vm)?;
|
||||
Ok(PySet { inner })
|
||||
}
|
||||
}
|
||||
|
||||
#[pyimpl(with(DictView, Comparable, Iterable))]
|
||||
impl PyDictValues {}
|
||||
|
||||
Reference in New Issue
Block a user