mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Add __contains__ in dict_items
This commit is contained in:
@@ -16,7 +16,7 @@ assert {'a': 123}.get('b') == None
|
||||
assert {'a': 123}.get('b', 456) == 456
|
||||
|
||||
d = {'a': 123, 'b': 456}
|
||||
|
||||
assert list(reversed(d)) == ['b', 'a']
|
||||
assert list(reversed(d.keys())) == ['b', 'a']
|
||||
assert list(reversed(d.values())) == [456, 123]
|
||||
assert list(reversed(d.items())) == [('b', 456), ('a', 123)]
|
||||
@@ -27,7 +27,13 @@ with assert_raises(StopIteration):
|
||||
assert 'dict' in dict().__doc__
|
||||
|
||||
d = {'a': 123, 'b': 456}
|
||||
assert 1 not in d.items()
|
||||
assert 'a' not in d.items()
|
||||
assert 'a', 123 not in d.items()
|
||||
assert () not in d.items()
|
||||
assert (1) not in d.items()
|
||||
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 () not in d.items()
|
||||
assert ('a', 123, 'b', 456) not in d.items()
|
||||
@@ -3,7 +3,7 @@ use super::{
|
||||
PyTypeRef,
|
||||
};
|
||||
use crate::{
|
||||
builtins::PyTupleRef,
|
||||
builtins::PyTuple,
|
||||
common::ascii,
|
||||
dictdatatype::{self, DictKey},
|
||||
function::{ArgIterable, FuncArgs, IntoPyObject, KwArgs, OptionalArg},
|
||||
@@ -985,7 +985,13 @@ impl PyDictItems {
|
||||
}
|
||||
|
||||
#[pymethod(magic)]
|
||||
fn contains(zelf: PyRef<Self>, needle: PyTupleRef, vm: &VirtualMachine) -> PyResult<bool> {
|
||||
fn contains(zelf: PyRef<Self>, needle: PyObjectRef, vm: &VirtualMachine) -> PyResult<bool> {
|
||||
let needle = match_class! {
|
||||
match needle {
|
||||
tuple @ PyTuple => tuple,
|
||||
_ => return Ok(false),
|
||||
}
|
||||
};
|
||||
if needle.len() != 2 {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user