mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Merge pull request #3271 from Jack-R-lantern/dict_key/__contains__
Add contains in dict_keys
This commit is contained in:
@@ -36,4 +36,15 @@ assert ('a') not in d.items()
|
||||
assert ('a', 123) in d.items()
|
||||
assert ('b', 456) in d.items()
|
||||
assert ('a', 123, 3) not in d.items()
|
||||
assert ('a', 123, 'b', 456) not in d.items()
|
||||
assert ('a', 123, 'b', 456) not in d.items()
|
||||
|
||||
d = {1: 10, "a": "ABC", (3,4): 5}
|
||||
assert 1 in d.keys()
|
||||
assert (1) in d.keys()
|
||||
assert "a" in d.keys()
|
||||
assert (3,4) in d.keys()
|
||||
assert () not in d.keys()
|
||||
assert 10 not in d.keys()
|
||||
assert (1, 10) not in d.keys()
|
||||
assert "abc" not in d.keys()
|
||||
assert ((3,4),5) not in d.keys()
|
||||
@@ -956,7 +956,12 @@ trait ViewSetOps: DictView {
|
||||
|
||||
impl ViewSetOps for PyDictKeys {}
|
||||
#[pyimpl(with(DictView, Comparable, Iterable, ViewSetOps))]
|
||||
impl PyDictKeys {}
|
||||
impl PyDictKeys {
|
||||
#[pymethod(magic)]
|
||||
fn contains(zelf: PyRef<Self>, key: PyObjectRef, vm: &VirtualMachine) -> PyResult<bool> {
|
||||
zelf.dict().contains(key, vm)
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewSetOps for PyDictItems {}
|
||||
#[pyimpl(with(DictView, Comparable, Iterable, ViewSetOps))]
|
||||
|
||||
Reference in New Issue
Block a user