Skip to content

Commit

Permalink
Fix some clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-N committed Apr 23, 2019
1 parent 77f0974 commit 6d87934
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/class/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -157,7 +157,7 @@ where
sq_contains: Self::sq_contains(),
sq_inplace_concat: Self::sq_inplace_concat(),
sq_inplace_repeat: Self::sq_inplace_repeat(),
});
})
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/types/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
18 changes: 18 additions & 0 deletions src/types/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 6d87934

Please sign in to comment.