Skip to content

Commit 3725b31

Browse files
committed
Make clippy happy
1 parent 1f88c84 commit 3725b31

File tree

13 files changed

+19
-29
lines changed

13 files changed

+19
-29
lines changed

examples/pyo3-pytests/src/buf_and_str.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,26 @@ impl BytesExtractor {
1414
BytesExtractor {}
1515
}
1616

17-
pub fn from_bytes(&mut self, bytes: &PyBytes) -> PyResult<usize> {
17+
#[staticmethod]
18+
pub fn from_bytes(bytes: &PyBytes) -> PyResult<usize> {
1819
let byte_vec: Vec<u8> = bytes.extract()?;
1920
Ok(byte_vec.len())
2021
}
2122

22-
pub fn from_str(&mut self, string: &PyString) -> PyResult<usize> {
23+
#[staticmethod]
24+
pub fn from_str(string: &PyString) -> PyResult<usize> {
2325
let rust_string: String = string.extract()?;
2426
Ok(rust_string.len())
2527
}
2628

27-
pub fn from_str_lossy(&mut self, string: &PyString) -> PyResult<usize> {
29+
#[staticmethod]
30+
pub fn from_str_lossy(string: &PyString) -> PyResult<usize> {
2831
let rust_string_lossy: String = string.to_string_lossy().to_string();
2932
Ok(rust_string_lossy.len())
3033
}
3134

32-
pub fn from_buffer(&mut self, buf: &PyAny) -> PyResult<usize> {
35+
#[staticmethod]
36+
pub fn from_buffer(buf: &PyAny) -> PyResult<usize> {
3337
let buf = PyBuffer::<u8>::get(buf)?;
3438
Ok(buf.item_count())
3539
}

pyo3-macros-backend/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
44
#![cfg_attr(docsrs, feature(doc_cfg))]
55
#![recursion_limit = "1024"]
6-
76
// Listed first so that macros in this module are available in the rest of the crate.
87
#[macro_use]
98
mod utils;

pyo3-macros-backend/src/method.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ impl<'a> FnArg<'a> {
2929
/// Transforms a rust fn arg parsed with syn into a method::FnArg
3030
pub fn parse(arg: &'a mut syn::FnArg) -> Result<Self> {
3131
match arg {
32-
syn::FnArg::Receiver(recv) => {
33-
bail_spanned!(recv.span() => "unexpected receiver")
34-
} // checked in parse_fn_type
32+
syn::FnArg::Receiver(recv) => bail_spanned!(recv.span() => "unexpected receiver"), // checked in parse_fn_type
3533
syn::FnArg::Typed(cap) => {
3634
if let syn::Type::ImplTrait(_) = &*cap.ty {
3735
bail_spanned!(cap.ty.span() => IMPL_TRAIT_ERR);
@@ -101,9 +99,7 @@ impl FnType {
10199
cls.expect("no class given for Fn with a \"self\" receiver"),
102100
error_mode,
103101
),
104-
FnType::FnNew | FnType::FnStatic | FnType::ClassAttribute => {
105-
quote!()
106-
}
102+
FnType::FnNew | FnType::FnStatic | FnType::ClassAttribute => quote!(),
107103
FnType::FnClass => {
108104
quote! {
109105
let _slf = ::pyo3::types::PyType::from_type_ptr(_py, _slf as *mut ::pyo3::ffi::PyTypeObject);
@@ -352,7 +348,8 @@ impl<'a> FnSpec<'a> {
352348
parse_method_receiver(first_arg)
353349
};
354350

355-
#[allow(clippy::manual_strip)] // for strip_prefix replacement supporting rust < 1.45
351+
#[allow(clippy::manual_strip)]
352+
// for strip_prefix replacement supporting rust < 1.45
356353
// strip get_ or set_
357354
let strip_fn_name = |prefix: &'static str| {
358355
let ident = name.unraw().to_string();

pyo3-macros-backend/src/params.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ fn impl_arg_param(
266266
}
267267
};
268268

269-
return if let syn::Type::Reference(tref) = unwrap_ty_group(arg.optional.unwrap_or(ty)) {
269+
if let syn::Type::Reference(tref) = unwrap_ty_group(arg.optional.unwrap_or(ty)) {
270270
let mut tref = remove_lifetime(tref);
271271
if let Some(cls) = self_ {
272272
replace_self(&mut tref.elem, cls);
@@ -298,5 +298,5 @@ fn impl_arg_param(
298298
Ok(quote_arg_span! {
299299
let #arg_name = #arg_value_or_default;
300300
})
301-
};
301+
}
302302
}

pyo3-macros-backend/src/pyimpl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn build_py_methods(
3636

3737
pub fn impl_methods(
3838
ty: &syn::Type,
39-
impls: &mut Vec<syn::ImplItem>,
39+
impls: &mut [syn::ImplItem],
4040
methods_type: PyClassMethodsType,
4141
) -> syn::Result<TokenStream> {
4242
let mut trait_impls = Vec::new();

pyo3-macros-backend/src/pymethod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,7 @@ pub fn gen_py_method(
138138
cls,
139139
PropertyType::Function { self_type, spec },
140140
)?),
141-
(_, FnType::FnModule) => {
142-
unreachable!("methods cannot be FnModule")
143-
}
141+
(_, FnType::FnModule) => unreachable!("methods cannot be FnModule"),
144142
})
145143
}
146144

pyo3-macros-backend/src/pyproto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn build_py_proto(ast: &mut syn::ItemImpl) -> syn::Result<TokenStream> {
4545

4646
fn impl_proto_impl(
4747
ty: &syn::Type,
48-
impls: &mut Vec<syn::ImplItem>,
48+
impls: &mut [syn::ImplItem],
4949
proto: &defs::Proto,
5050
) -> syn::Result<TokenStream> {
5151
let mut trait_impls = TokenStream::new();

src/conversion.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ where
195195
/// }
196196
/// }
197197
/// }
198-
/// # fn main() {
199198
/// # Python::with_gil(|py| {
200199
/// # let v = Value::Integer(73).into_py(py);
201200
/// # let v = v.extract::<i32>(py).unwrap();
@@ -206,7 +205,6 @@ where
206205
/// # let v = Value::None.into_py(py);
207206
/// # let v = v.extract::<Option<Vec<i32>>>(py).unwrap();
208207
/// # });
209-
/// # }
210208
/// ```
211209
/// Python code will see this as any of the `int`, `string` or `None` objects.
212210
#[cfg_attr(docsrs, doc(alias = "IntoPyCallbackOutput"))]

src/ffi/pyhash.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extern "C" {
1414
pub fn _Py_HashBytes(src: *const c_void, len: Py_ssize_t) -> Py_hash_t;
1515
}
1616

17-
pub const _PyHASH_MULTIPLIER: c_ulong = 1000003;
17+
pub const _PyHASH_MULTIPLIER: c_ulong = 1_000_003;
1818

1919
// skipped _PyHASH_BITS
2020

src/instance.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ pub unsafe trait PyNativeType: Sized {
172172
/// use pyo3::prelude::*;
173173
/// use pyo3::types::PyDict;
174174
///
175-
/// # fn main() {
176175
/// Python::with_gil(|py| {
177176
/// let first: Py<PyDict> = PyDict::new(py).into();
178177
///
@@ -190,7 +189,6 @@ pub unsafe trait PyNativeType: Sized {
190189
/// assert_eq!(fourth.as_ptr(), fifth.as_ptr());
191190
/// assert_eq!(second.as_ptr(), fourth.as_ptr());
192191
/// });
193-
/// # }
194192
/// ```
195193
///
196194
/// # Preventing reference cycles
@@ -479,15 +477,13 @@ impl<T> Py<T> {
479477
/// use pyo3::prelude::*;
480478
/// use pyo3::types::PyDict;
481479
///
482-
/// # fn main() {
483480
/// Python::with_gil(|py| {
484481
/// let first: Py<PyDict> = PyDict::new(py).into();
485482
/// let second = Py::clone_ref(&first, py);
486483
///
487484
/// // Both point to the same object
488485
/// assert_eq!(first.as_ptr(), second.as_ptr());
489486
/// });
490-
/// # }
491487
/// ```
492488
#[inline]
493489
pub fn clone_ref(&self, py: Python) -> Py<T> {

0 commit comments

Comments
 (0)