From faa21f48c7629a57cf0563d6f8a500acd9dd84d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Niederb=C3=BChl?= Date: Sun, 14 Jul 2019 22:02:01 +0200 Subject: [PATCH 1/3] Fix some clippy lints --- pyo3-derive-backend/src/pyproto.rs | 4 ++-- src/class/basic.rs | 4 ++-- src/types/tuple.rs | 7 ++----- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/pyo3-derive-backend/src/pyproto.rs b/pyo3-derive-backend/src/pyproto.rs index f33193e8897..a80da75cb6c 100644 --- a/pyo3-derive-backend/src/pyproto.rs +++ b/pyo3-derive-backend/src/pyproto.rs @@ -47,10 +47,10 @@ pub fn build_py_proto(ast: &mut syn::ItemImpl) -> syn::Result { Ok(tokens) } else { - return Err(syn::Error::new_spanned( + Err(syn::Error::new_spanned( ast, "#[pyproto] can only be used with protocol trait implementations", - )); + )) } } diff --git a/src/class/basic.rs b/src/class/basic.rs index a23c271801a..cc300535e44 100644 --- a/src/class/basic.rs +++ b/src/class/basic.rs @@ -221,7 +221,7 @@ where // Behave like python's __getattr__ (as opposed to __getattribute__) and check // for existing fields and methods first let existing = ffi::PyObject_GenericGetAttr(slf, arg); - if existing == std::ptr::null_mut() { + if existing.is_null() { // PyObject_HasAttr also tries to get an object and clears the error if it fails ffi::PyErr_Clear(); } else { @@ -233,7 +233,7 @@ where let result = match arg.extract() { Ok(arg) => slf.__getattr__(arg).into(), - Err(e) => Err(e.into()), + Err(e) => Err(e), }; crate::callback::cb_convert(PyObjectCallbackConverter, py, result) } diff --git a/src/types/tuple.rs b/src/types/tuple.rs index 9e259d1a9d6..26ac3c0fa18 100644 --- a/src/types/tuple.rs +++ b/src/types/tuple.rs @@ -21,10 +21,7 @@ pyobject_native_type!(PyTuple, ffi::PyTuple_Type, ffi::PyTuple_Check); impl PyTuple { /// Construct a new tuple with the given elements. - pub fn new<'p, T, U>( - py: Python<'p>, - elements: impl IntoIterator, - ) -> &'p PyTuple + pub fn new(py: Python, elements: impl IntoIterator) -> &PyTuple where T: ToPyObject, U: ExactSizeIterator, @@ -41,7 +38,7 @@ impl PyTuple { } /// Retrieves the empty tuple. - pub fn empty<'p>(py: Python<'p>) -> &'p PyTuple { + pub fn empty(py: Python) -> &PyTuple { unsafe { py.from_owned_ptr(ffi::PyTuple_New(0)) } } From cc31c7dbf251744f21e2be6ef711611d9bb07488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Niederb=C3=BChl?= Date: Sun, 14 Jul 2019 22:05:55 +0200 Subject: [PATCH 2/3] Ignore remaining clippy lints --- src/python.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/python.rs b/src/python.rs index 764cef80cf3..021d1193ef3 100644 --- a/src/python.rs +++ b/src/python.rs @@ -234,6 +234,7 @@ impl<'p> Python<'p> { } /// Register `ffi::PyObject` pointer in release pool + #[allow(clippy::wrong_self_convention)] pub unsafe fn from_borrowed_ptr_to_obj(self, ptr: *mut ffi::PyObject) -> &'p PyAny { match NonNull::new(ptr) { Some(p) => gil::register_borrowed(self, p), @@ -243,6 +244,7 @@ impl<'p> Python<'p> { /// Register `ffi::PyObject` pointer in release pool, /// and do unchecked downcast to specific type. + #[allow(clippy::wrong_self_convention)] pub unsafe fn from_owned_ptr(self, ptr: *mut ffi::PyObject) -> &'p T where T: PyTypeInfo, @@ -262,6 +264,7 @@ impl<'p> Python<'p> { /// Register owned `ffi::PyObject` pointer in release pool. /// Returns `Err(PyErr)` if the pointer is `null`. /// do unchecked downcast to specific type. + #[allow(clippy::wrong_self_convention)] pub unsafe fn from_owned_ptr_or_err(self, ptr: *mut ffi::PyObject) -> PyResult<&'p T> where T: PyTypeInfo, @@ -272,6 +275,7 @@ impl<'p> Python<'p> { /// Register owned `ffi::PyObject` pointer in release pool. /// Returns `None` if the pointer is `null`. /// do unchecked downcast to specific type. + #[allow(clippy::wrong_self_convention)] pub unsafe fn from_owned_ptr_or_opt(self, ptr: *mut ffi::PyObject) -> Option<&'p T> where T: PyTypeInfo, @@ -282,6 +286,7 @@ impl<'p> Python<'p> { /// Register borrowed `ffi::PyObject` pointer in release pool. /// Panics if the pointer is `null`. /// do unchecked downcast to specific type. + #[allow(clippy::wrong_self_convention)] pub unsafe fn from_borrowed_ptr(self, ptr: *mut ffi::PyObject) -> &'p T where T: PyTypeInfo, @@ -302,6 +307,7 @@ impl<'p> Python<'p> { /// Register borrowed `ffi::PyObject` pointer in release pool. /// Returns `Err(PyErr)` if the pointer is `null`. /// do unchecked downcast to specific type. + #[allow(clippy::wrong_self_convention)] pub unsafe fn from_borrowed_ptr_or_err(self, ptr: *mut ffi::PyObject) -> PyResult<&'p T> where T: PyTypeInfo, @@ -312,6 +318,7 @@ impl<'p> Python<'p> { /// Register borrowed `ffi::PyObject` pointer in release pool. /// Returns `None` if the pointer is `null`. /// do unchecked downcast to specific `T`. + #[allow(clippy::wrong_self_convention)] pub unsafe fn from_borrowed_ptr_or_opt(self, ptr: *mut ffi::PyObject) -> Option<&'p T> where T: PyTypeInfo, From 86cc424b232e35231ea1a89bdcf620142b2683af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Niederb=C3=BChl?= Date: Sun, 14 Jul 2019 22:37:45 +0200 Subject: [PATCH 3/3] Fail CI if there are clippy warnings --- ci/travis/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/travis/test.sh b/ci/travis/test.sh index f7c4f9fbf50..3169c44ab6d 100755 --- a/ci/travis/test.sh +++ b/ci/travis/test.sh @@ -12,7 +12,7 @@ fi if [ "$TRAVIS_JOB_NAME" = "Minimum nightly" ]; then cargo fmt --all -- --check - cargo clippy --features "$FEATURES num-complex" + cargo clippy --features "$FEATURES num-complex" -- -D warnings fi for example_dir in examples/*; do