Fix some clippy lints
This commit is contained in:
parent
77f0974daf
commit
6d87934ce0
|
@ -146,7 +146,7 @@ where
|
|||
T: PySequenceProtocol<'p>,
|
||||
{
|
||||
fn tp_as_sequence() -> Option<ffi::PySequenceMethods> {
|
||||
return Some(ffi::PySequenceMethods {
|
||||
Some(ffi::PySequenceMethods {
|
||||
sq_length: Self::sq_length(),
|
||||
sq_concat: Self::sq_concat(),
|
||||
sq_repeat: Self::sq_repeat(),
|
||||
|
@ -157,7 +157,7 @@ where
|
|||
sq_contains: Self::sq_contains(),
|
||||
sq_inplace_concat: Self::sq_inplace_concat(),
|
||||
sq_inplace_repeat: Self::sq_inplace_repeat(),
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,10 +20,7 @@ pyobject_native_type!(PyList, ffi::PyList_Type, ffi::PyList_Check);
|
|||
|
||||
impl PyList {
|
||||
/// Construct a new list with the given elements.
|
||||
pub fn new<'p, T, U>(
|
||||
py: Python<'p>,
|
||||
elements: impl IntoIterator<Item = T, IntoIter = U>,
|
||||
) -> &'p PyList
|
||||
pub fn new<T, U>(py: Python<'_>, elements: impl IntoIterator<Item = T, IntoIter = U>) -> &PyList
|
||||
where
|
||||
T: ToPyObject,
|
||||
U: ExactSizeIterator<Item = T>,
|
||||
|
|
|
@ -27,6 +27,11 @@ impl PySequence {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_empty(&self) -> PyResult<bool> {
|
||||
self.len().map(|l| l == 0)
|
||||
}
|
||||
|
||||
/// Return the concatenation of o1 and o2. Equivalent to python `o1 + o2`
|
||||
#[inline]
|
||||
pub fn concat(&self, other: &PySequence) -> PyResult<&PySequence> {
|
||||
|
@ -656,4 +661,17 @@ mod test {
|
|||
let seq_from = unsafe { <PySequence as PyTryFrom>::try_from_unchecked(type_ptr) };
|
||||
assert!(seq_from.list().is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_empty() {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
let list = vec![1].to_object(py);
|
||||
let seq = list.cast_as::<PySequence>(py).unwrap();
|
||||
assert_eq!(seq.is_empty().unwrap(), false);
|
||||
let vec: Vec<u32> = Vec::new();
|
||||
let empty_list = vec.to_object(py);
|
||||
let empty_seq = empty_list.cast_as::<PySequence>(py).unwrap();
|
||||
assert_eq!(empty_seq.is_empty().unwrap(), true);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue