Skip to content

Commit

Permalink
make clippy more happy and format the world
Browse files Browse the repository at this point in the history
  • Loading branch information
mejrs committed Apr 12, 2022
1 parent f0d2c7d commit d80e451
Show file tree
Hide file tree
Showing 26 changed files with 64 additions and 71 deletions.
12 changes: 8 additions & 4 deletions examples/pyo3-pytests/src/buf_and_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,26 @@ impl BytesExtractor {
BytesExtractor {}
}

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

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

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

pub fn from_buffer(&mut self, buf: &PyAny) -> PyResult<usize> {
#[staticmethod]
pub fn from_buffer(buf: &PyAny) -> PyResult<usize> {
let buf = PyBuffer::<u8>::get(buf)?;
Ok(buf.item_count())
}
Expand Down
2 changes: 1 addition & 1 deletion pyo3-macros-backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#![cfg_attr(docsrs, feature(doc_cfg))]
#![recursion_limit = "1024"]

#![allow(clippy::unknown_clippy_lints)]
// Listed first so that macros in this module are available in the rest of the crate.
#[macro_use]
mod utils;
Expand Down
11 changes: 4 additions & 7 deletions pyo3-macros-backend/src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ impl<'a> FnArg<'a> {
/// Transforms a rust fn arg parsed with syn into a method::FnArg
pub fn parse(arg: &'a mut syn::FnArg) -> Result<Self> {
match arg {
syn::FnArg::Receiver(recv) => {
bail_spanned!(recv.span() => "unexpected receiver")
} // checked in parse_fn_type
syn::FnArg::Receiver(recv) => bail_spanned!(recv.span() => "unexpected receiver"), // checked in parse_fn_type
syn::FnArg::Typed(cap) => {
if let syn::Type::ImplTrait(_) = &*cap.ty {
bail_spanned!(cap.ty.span() => IMPL_TRAIT_ERR);
Expand Down Expand Up @@ -101,9 +99,7 @@ impl FnType {
cls.expect("no class given for Fn with a \"self\" receiver"),
error_mode,
),
FnType::FnNew | FnType::FnStatic | FnType::ClassAttribute => {
quote!()
}
FnType::FnNew | FnType::FnStatic | FnType::ClassAttribute => quote!(),
FnType::FnClass => {
quote! {
let _slf = ::pyo3::types::PyType::from_type_ptr(_py, _slf as *mut ::pyo3::ffi::PyTypeObject);
Expand Down Expand Up @@ -352,7 +348,8 @@ impl<'a> FnSpec<'a> {
parse_method_receiver(first_arg)
};

#[allow(clippy::manual_strip)] // for strip_prefix replacement supporting rust < 1.45
#[allow(clippy::manual_strip)]
// for strip_prefix replacement supporting rust < 1.45
// strip get_ or set_
let strip_fn_name = |prefix: &'static str| {
let ident = name.unraw().to_string();
Expand Down
4 changes: 2 additions & 2 deletions pyo3-macros-backend/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ fn impl_arg_param(
}
};

return if let syn::Type::Reference(tref) = unwrap_ty_group(arg.optional.unwrap_or(ty)) {
if let syn::Type::Reference(tref) = unwrap_ty_group(arg.optional.unwrap_or(ty)) {
let mut tref = remove_lifetime(tref);
if let Some(cls) = self_ {
replace_self(&mut tref.elem, cls);
Expand Down Expand Up @@ -298,5 +298,5 @@ fn impl_arg_param(
Ok(quote_arg_span! {
let #arg_name = #arg_value_or_default;
})
};
}
}
4 changes: 1 addition & 3 deletions pyo3-macros-backend/src/pymethod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ pub fn gen_py_method(
cls,
PropertyType::Function { self_type, spec },
)?),
(_, FnType::FnModule) => {
unreachable!("methods cannot be FnModule")
}
(_, FnType::FnModule) => unreachable!("methods cannot be FnModule"),
})
}

Expand Down
2 changes: 0 additions & 2 deletions src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ where
/// }
/// }
/// }
/// # fn main() {
/// # Python::with_gil(|py| {
/// # let v = Value::Integer(73).into_py(py);
/// # let v = v.extract::<i32>(py).unwrap();
Expand All @@ -206,7 +205,6 @@ where
/// # let v = Value::None.into_py(py);
/// # let v = v.extract::<Option<Vec<i32>>>(py).unwrap();
/// # });
/// # }
/// ```
/// Python code will see this as any of the `int`, `string` or `None` objects.
#[cfg_attr(docsrs, doc(alias = "IntoPyCallbackOutput"))]
Expand Down
4 changes: 2 additions & 2 deletions src/ffi/codecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ extern "C" {
pub fn PyCodec_ReplaceErrors(exc: *mut PyObject) -> *mut PyObject;
pub fn PyCodec_XMLCharRefReplaceErrors(exc: *mut PyObject) -> *mut PyObject;
pub fn PyCodec_BackslashReplaceErrors(exc: *mut PyObject) -> *mut PyObject;
// skipped non-limited PyCodec_NameReplaceErrors from Include/codecs.h
// skipped non-limited Py_hexdigits from Include/codecs.h
// skipped non-limited PyCodec_NameReplaceErrors from Include/codecs.h
// skipped non-limited Py_hexdigits from Include/codecs.h
}
4 changes: 2 additions & 2 deletions src/ffi/complexobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ extern "C" {
pub fn PyComplex_RealAsDouble(op: *mut PyObject) -> c_double;
#[cfg_attr(PyPy, link_name = "PyPyComplex_ImagAsDouble")]
pub fn PyComplex_ImagAsDouble(op: *mut PyObject) -> c_double;
// skipped non-limited PyComplex_AsCComplex
// skipped non-limited _PyComplex_FormatAdvancedWriter
// skipped non-limited PyComplex_AsCComplex
// skipped non-limited _PyComplex_FormatAdvancedWriter
}
4 changes: 2 additions & 2 deletions src/ffi/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern "C" {
pub static mut PyContextVar_Type: PyTypeObject;
// skipped non-limited opaque PyContextVar
pub static mut PyContextToken_Type: PyTypeObject;
// skipped non-limited opaque PyContextToken
// skipped non-limited opaque PyContextToken
}

#[inline]
Expand Down Expand Up @@ -41,5 +41,5 @@ extern "C" {
) -> c_int;
pub fn PyContextVar_Set(var: *mut PyObject, value: *mut PyObject) -> *mut PyObject;
pub fn PyContextVar_Reset(var: *mut PyObject, token: *mut PyObject) -> c_int;
// skipped non-limited _PyContext_NewHamtForTests
// skipped non-limited _PyContext_NewHamtForTests
}
4 changes: 2 additions & 2 deletions src/ffi/cpython/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ extern "C" {
#[cfg(Py_3_8)]
pub fn PyCompile_OpcodeStackEffectWithJump(opcode: c_int, oparg: c_int, jump: c_int) -> c_int;

// skipped non-limited _PyASTOptimizeState
// skipped non-limited _PyAST_Optimize
// skipped non-limited _PyASTOptimizeState
// skipped non-limited _PyAST_Optimize
}
6 changes: 3 additions & 3 deletions src/ffi/cpython/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,9 @@ extern "C" {
#[cfg_attr(PyPy, link_name = "PyPyObject_CallFinalizerFromDealloc")]
pub fn PyObject_CallFinalizerFromDealloc(arg1: *mut PyObject) -> c_int;

// skipped _PyObject_GenericGetAttrWithDict
// skipped _PyObject_GenericSetAttrWithDict
// skipped _PyObject_FunctionStr
// skipped _PyObject_GenericGetAttrWithDict
// skipped _PyObject_GenericSetAttrWithDict
// skipped _PyObject_FunctionStr
}

// skipped Py_SETREF
Expand Down
28 changes: 14 additions & 14 deletions src/ffi/cpython/pylifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@ extern "C" {

pub fn Py_RunMain() -> c_int;

// skipped Py_ExitStatusException
// skipped Py_ExitStatusException

// skipped _Py_RestoreSignals
// skipped _Py_RestoreSignals

// skipped Py_FdIsInteractive
// skipped _Py_FdIsInteractive
// skipped Py_FdIsInteractive
// skipped _Py_FdIsInteractive

// skipped _Py_SetProgramFullPath
// skipped _Py_SetProgramFullPath

// skipped _Py_gitidentifier
// skipped _Py_getversion
// skipped _Py_gitidentifier
// skipped _Py_getversion

// skipped _Py_IsFinalizing
// skipped _Py_IsFinalizing

// skipped _PyOS_URandom
// skipped _PyOS_URandomNonblock
// skipped _PyOS_URandom
// skipped _PyOS_URandomNonblock

// skipped _Py_CoerceLegacyLocale
// skipped _Py_LegacyLocaleDetected
// skipped _Py_SetLocaleFromEnv
// skipped _Py_CoerceLegacyLocale
// skipped _Py_LegacyLocaleDetected
// skipped _Py_SetLocaleFromEnv

// skipped _Py_NewInterpreter
// skipped _Py_NewInterpreter
}
8 changes: 4 additions & 4 deletions src/ffi/cpython/pymem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ extern "C" {
#[cfg_attr(PyPy, link_name = "PyPyMem_RawFree")]
pub fn PyMem_RawFree(ptr: *mut c_void);

// skipped _PyMem_GetCurrentAllocatorName
// skipped _PyMem_RawStrdup
// skipped _PyMem_Strdup
// skipped _PyMem_RawWcsdup
// skipped _PyMem_GetCurrentAllocatorName
// skipped _PyMem_RawStrdup
// skipped _PyMem_Strdup
// skipped _PyMem_RawWcsdup
}

#[repr(C)]
Expand Down
4 changes: 2 additions & 2 deletions src/ffi/cpython/unicodeobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ extern "C" {
size: *mut Py_ssize_t,
) -> *mut Py_UNICODE;

// skipped PyUnicode_GetMax
// skipped PyUnicode_GetMax
}

// skipped _PyUnicodeWriter
Expand Down Expand Up @@ -437,7 +437,7 @@ extern "C" {
length: Py_ssize_t,
) -> *mut PyObject;

// skipped _PyUnicode_TransformDecimalAndSpaceToASCII
// skipped _PyUnicode_TransformDecimalAndSpaceToASCII
}

// skipped _PyUnicode_JoinArray
Expand Down
2 changes: 1 addition & 1 deletion src/ffi/descrobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extern "C" {
pub static mut PyWrapperDescr_Type: PyTypeObject;
#[cfg_attr(PyPy, link_name = "PyPyDictProxy_Type")]
pub static mut PyDictProxy_Type: PyTypeObject;
// skipped non-limited _PyMethodWrapper_Type
// skipped non-limited _PyMethodWrapper_Type
}

extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion src/ffi/dictobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ extern "C" {
) -> c_int;
#[cfg_attr(PyPy, link_name = "PyPyDict_DelItemString")]
pub fn PyDict_DelItemString(dp: *mut PyObject, key: *const c_char) -> c_int;
// skipped 3.10 / ex-non-limited PyObject_GenericGetDict
// skipped 3.10 / ex-non-limited PyObject_GenericGetDict
}

#[cfg_attr(windows, link(name = "pythonXY"))]
Expand Down
4 changes: 2 additions & 2 deletions src/ffi/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ extern "C" {
closure: *mut PyObject,
) -> *mut PyObject;

// skipped non-limited _PyEval_EvalCodeWithName
// skipped non-limited _PyEval_CallTracing
// skipped non-limited _PyEval_EvalCodeWithName
// skipped non-limited _PyEval_CallTracing
}
2 changes: 1 addition & 1 deletion src/ffi/fileobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extern "C" {
pub static mut Py_FileSystemDefaultEncoding: *const c_char;
pub static mut Py_FileSystemDefaultEncodeErrors: *const c_char;
pub static mut Py_HasFileSystemDefaultEncoding: c_int;
// skipped Python 3.7 / ex-non-limited Py_UTF8Mode
// skipped Python 3.7 / ex-non-limited Py_UTF8Mode
}

// skipped _PyIsSelectable_fd
6 changes: 3 additions & 3 deletions src/ffi/genobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ pub unsafe fn PyCoro_CheckExact(op: *mut PyObject) -> c_int {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyAsyncGen_Type: PyTypeObject;
// skipped _PyAsyncGenASend_Type
// skipped _PyAsyncGenWrappedValue_Type
// skipped _PyAsyncGenAThrow_Type
// skipped _PyAsyncGenASend_Type
// skipped _PyAsyncGenWrappedValue_Type
// skipped _PyAsyncGenAThrow_Type
}

// skipped PyAsyncGen_New
Expand Down
4 changes: 2 additions & 2 deletions src/ffi/intrcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ extern "C" {
#[cfg_attr(PyPy, link_name = "PyPyOS_AfterFork")]
pub fn PyOS_AfterFork();

// skipped non-limited _PyOS_IsMainThread
// skipped non-limited Windows _PyOS_SigintEvent
// skipped non-limited _PyOS_IsMainThread
// skipped non-limited Windows _PyOS_SigintEvent
}
6 changes: 3 additions & 3 deletions src/ffi/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ extern "C" {
#[cfg_attr(PyPy, link_name = "PyPyType_GetSlot")]
pub fn PyType_GetSlot(arg1: *mut PyTypeObject, arg2: c_int) -> *mut c_void;

// skipped non-limited / 3.9 PyType_FromModuleAndSpec
// skipped non-limited / 3.9 PyType_GetModule
// skipped non-limited / 3.9 PyType_GetModuleState
// skipped non-limited / 3.9 PyType_FromModuleAndSpec
// skipped non-limited / 3.9 PyType_GetModule
// skipped non-limited / 3.9 PyType_GetModuleState
}

extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion src/ffi/pyhash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extern "C" {
pub fn _Py_HashBytes(src: *const c_void, len: Py_ssize_t) -> Py_hash_t;
}

pub const _PyHASH_MULTIPLIER: c_ulong = 1000003;
pub const _PyHASH_MULTIPLIER: c_ulong = 1_000_003;

// skipped _PyHASH_BITS

Expand Down
2 changes: 1 addition & 1 deletion src/ffi/setobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extern "C" {
hash: *mut super::Py_hash_t,
) -> c_int;

// skipped non-limited _PySet_Update
// skipped non-limited _PySet_Update
}

#[cfg_attr(windows, link(name = "pythonXY"))]
Expand Down
4 changes: 0 additions & 4 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ pub unsafe trait PyNativeType: Sized {
/// use pyo3::prelude::*;
/// use pyo3::types::PyDict;
///
/// # fn main() {
/// Python::with_gil(|py| {
/// let first: Py<PyDict> = PyDict::new(py).into();
///
Expand All @@ -190,7 +189,6 @@ pub unsafe trait PyNativeType: Sized {
/// assert_eq!(fourth.as_ptr(), fifth.as_ptr());
/// assert_eq!(second.as_ptr(), fourth.as_ptr());
/// });
/// # }
/// ```
///
/// # Preventing reference cycles
Expand Down Expand Up @@ -479,15 +477,13 @@ impl<T> Py<T> {
/// use pyo3::prelude::*;
/// use pyo3::types::PyDict;
///
/// # fn main() {
/// Python::with_gil(|py| {
/// let first: Py<PyDict> = PyDict::new(py).into();
/// let second = Py::clone_ref(&first, py);
///
/// // Both point to the same object
/// assert_eq!(first.as_ptr(), second.as_ptr());
/// });
/// # }
/// ```
#[inline]
pub fn clone_ref(&self, py: Python) -> Py<T> {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// Deny some lints in doctests.
// Use `#[allow(...)]` locally to override.
#![doc(test(attr(deny(warnings), allow(unused_variables, unused_assignments))))]

#![allow(clippy::unknown_clippy_lints)] // So many new lints...
//! Rust bindings to the Python interpreter.
//!
//! PyO3 can be used to write native Python modules or run Python code and modules from Rust.
Expand Down
2 changes: 1 addition & 1 deletion src/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl PanicException {
if let Some(string) = payload.downcast_ref::<String>() {
Self::new_err((string.clone(),))
} else if let Some(s) = payload.downcast_ref::<&str>() {
Self::new_err((s.to_string(),))
Self::new_err(((*s).to_string(),))
} else {
Self::new_err(("panic from Rust code",))
}
Expand Down

0 comments on commit d80e451

Please sign in to comment.