Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some clippy lints #455

Merged
merged 1 commit into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a new grammar?
Great.

Copy link
Member

@kngwyu kngwyu Apr 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh it was stabilized a year ago rust-lang/rust#49458.
Maybe I have to learn Rust once more 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The edition guide and the official rust blog (esp. the release notes) are really good resources for that

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);
}
}