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

clippy: tidy up allow lints #1559

Merged
merged 1 commit into from
Apr 12, 2021
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
3 changes: 1 addition & 2 deletions src/class/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ macro_rules! py_binary_self_func {
$crate::callback_body!(py, {
let slf_ = py.from_borrowed_ptr::<$crate::PyCell<T>>(slf);
let arg = py.from_borrowed_ptr::<$crate::PyAny>(arg);
#[allow(clippy::needless_question_mark)]
call_operator_mut!(py, slf_, $f, arg).convert(py)?;
ffi::Py_INCREF(slf);
Ok::<_, $crate::err::PyErr>(slf)
Expand Down Expand Up @@ -342,7 +341,7 @@ macro_rules! _call_impl {
$slf, $fn ;
(match $raw_arg.extract() {
Ok(res) => res,
_=> return Ok($py.NotImplemented().convert($py)?)
_=> return $py.NotImplemented().convert($py)
})
$(;$args)*
)
Expand Down
1 change: 0 additions & 1 deletion src/class/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,6 @@ where
crate::callback_body!(py, {
let slf_cell = py.from_borrowed_ptr::<crate::PyCell<T>>(slf);
let other = py.from_borrowed_ptr::<crate::PyAny>(other);
#[allow(clippy::needless_question_mark)]
call_operator_mut!(py, slf_cell, __ipow__, other).convert(py)?;
ffi::Py_INCREF(slf);
Ok::<_, PyErr>(slf)
Expand Down
86 changes: 1 addition & 85 deletions src/ffi/compile.rs
Original file line number Diff line number Diff line change
@@ -1,88 +1,4 @@
use crate::ffi::object::PyObject;
use crate::ffi::pyarena::*;
use crate::ffi::pythonrun::*;
use crate::ffi::PyCodeObject;
use std::os::raw::{c_char, c_int};

// skipped non-limited PyCF_MASK
// skipped non-limited PyCF_MASK_OBSOLETE
// skipped non-limited PyCF_SOURCE_IS_UTF8
// skipped non-limited PyCF_DONT_IMPLY_DEDENT
// skipped non-limited PyCF_ONLY_AST
// skipped non-limited PyCF_IGNORE_COOKIE
// skipped non-limited PyCF_TYPE_COMMENTS
// skipped non-limited PyCF_ALLOW_TOP_LEVEL_AWAIT
// skipped non-limited PyCF_COMPILE_MASK

// skipped non-limited PyCompilerFlags
// skipped non-limited _PyCompilerFlags_INIT

#[repr(C)]
#[derive(Copy, Clone)]
#[cfg(not(Py_LIMITED_API))]
pub struct PyFutureFeatures {
pub ff_features: c_int,
pub ff_lineno: c_int,
}

#[cfg(not(Py_LIMITED_API))]
pub const FUTURE_NESTED_SCOPES: &str = "nested_scopes";
#[cfg(not(Py_LIMITED_API))]
pub const FUTURE_GENERATORS: &str = "generators";
#[cfg(not(Py_LIMITED_API))]
pub const FUTURE_DIVISION: &str = "division";
#[cfg(not(Py_LIMITED_API))]
pub const FUTURE_ABSOLUTE_IMPORT: &str = "absolute_import";
#[cfg(not(Py_LIMITED_API))]
pub const FUTURE_WITH_STATEMENT: &str = "with_statement";
#[cfg(not(Py_LIMITED_API))]
pub const FUTURE_PRINT_FUNCTION: &str = "print_function";
#[cfg(not(Py_LIMITED_API))]
pub const FUTURE_UNICODE_LITERALS: &str = "unicode_literals";
#[cfg(not(Py_LIMITED_API))]
pub const FUTURE_BARRY_AS_BDFL: &str = "barry_as_FLUFL";
#[cfg(not(Py_LIMITED_API))]
pub const FUTURE_GENERATOR_STOP: &str = "generator_stop";
// skipped non-limited FUTURE_ANNOTATIONS

#[cfg(not(Py_LIMITED_API))]
extern "C" {
pub fn PyNode_Compile(arg1: *mut _node, arg2: *const c_char) -> *mut PyCodeObject;

pub fn PyAST_CompileEx(
_mod: *mut _mod,
filename: *const c_char,
flags: *mut PyCompilerFlags,
optimize: c_int,
arena: *mut PyArena,
) -> *mut PyCodeObject;

pub fn PyAST_CompileObject(
_mod: *mut _mod,
filename: *mut PyObject,
flags: *mut PyCompilerFlags,
optimize: c_int,
arena: *mut PyArena,
) -> *mut PyCodeObject;

pub fn PyFuture_FromAST(_mod: *mut _mod, filename: *const c_char) -> *mut PyFutureFeatures;

pub fn PyFuture_FromASTObject(
_mod: *mut _mod,
filename: *mut PyObject,
) -> *mut PyFutureFeatures;

// skipped non-limited _Py_Mangle
// skipped non-limited PY_INVALID_STACK_EFFECT

pub fn PyCompile_OpcodeStackEffect(opcode: c_int, oparg: c_int) -> c_int;

#[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
}
use std::os::raw::c_int;

pub const Py_single_input: c_int = 256;
pub const Py_file_input: c_int = 257;
Expand Down
74 changes: 74 additions & 0 deletions src/ffi/cpython/compile.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use crate::ffi::object::PyObject;
use crate::ffi::pyarena::*;
use crate::ffi::pythonrun::*;
use crate::ffi::PyCodeObject;
use std::os::raw::{c_char, c_int};

// skipped non-limited PyCF_MASK
// skipped non-limited PyCF_MASK_OBSOLETE
// skipped non-limited PyCF_SOURCE_IS_UTF8
// skipped non-limited PyCF_DONT_IMPLY_DEDENT
// skipped non-limited PyCF_ONLY_AST
// skipped non-limited PyCF_IGNORE_COOKIE
// skipped non-limited PyCF_TYPE_COMMENTS
// skipped non-limited PyCF_ALLOW_TOP_LEVEL_AWAIT
// skipped non-limited PyCF_COMPILE_MASK

// skipped non-limited PyCompilerFlags
// skipped non-limited _PyCompilerFlags_INIT

#[repr(C)]
#[derive(Copy, Clone)]
pub struct PyFutureFeatures {
pub ff_features: c_int,
pub ff_lineno: c_int,
}

pub const FUTURE_NESTED_SCOPES: &str = "nested_scopes";
pub const FUTURE_GENERATORS: &str = "generators";
pub const FUTURE_DIVISION: &str = "division";
pub const FUTURE_ABSOLUTE_IMPORT: &str = "absolute_import";
pub const FUTURE_WITH_STATEMENT: &str = "with_statement";
pub const FUTURE_PRINT_FUNCTION: &str = "print_function";
pub const FUTURE_UNICODE_LITERALS: &str = "unicode_literals";
pub const FUTURE_BARRY_AS_BDFL: &str = "barry_as_FLUFL";
pub const FUTURE_GENERATOR_STOP: &str = "generator_stop";
// skipped non-limited FUTURE_ANNOTATIONS

extern "C" {
pub fn PyNode_Compile(arg1: *mut _node, arg2: *const c_char) -> *mut PyCodeObject;

pub fn PyAST_CompileEx(
_mod: *mut _mod,
filename: *const c_char,
flags: *mut PyCompilerFlags,
optimize: c_int,
arena: *mut PyArena,
) -> *mut PyCodeObject;

pub fn PyAST_CompileObject(
_mod: *mut _mod,
filename: *mut PyObject,
flags: *mut PyCompilerFlags,
optimize: c_int,
arena: *mut PyArena,
) -> *mut PyCodeObject;

pub fn PyFuture_FromAST(_mod: *mut _mod, filename: *const c_char) -> *mut PyFutureFeatures;

pub fn PyFuture_FromASTObject(
_mod: *mut _mod,
filename: *mut PyObject,
) -> *mut PyFutureFeatures;

// skipped non-limited _Py_Mangle
// skipped non-limited PY_INVALID_STACK_EFFECT

pub fn PyCompile_OpcodeStackEffect(opcode: c_int, oparg: c_int) -> c_int;

#[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
}
4 changes: 4 additions & 0 deletions src/ffi/cpython/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod abstract_;
pub mod bytesobject;
pub mod ceval;
pub mod code;
pub mod compile;
#[cfg(not(PyPy))]
pub mod dictobject;
// skipped fileobject.h
Expand All @@ -14,6 +15,7 @@ pub mod initconfig;
// skipped interpreteridobject.h
pub mod listobject;
pub mod object;
pub mod pydebug;
#[cfg(all(Py_3_8, not(PyPy)))]
pub mod pylifecycle;

Expand All @@ -22,12 +24,14 @@ pub use self::abstract_::*;
pub use self::bytesobject::*;
pub use self::ceval::*;
pub use self::code::*;
pub use self::compile::*;
#[cfg(not(PyPy))]
pub use self::dictobject::*;
pub use self::frameobject::*;
#[cfg(all(Py_3_8, not(PyPy)))]
pub use self::initconfig::*;
pub use self::listobject::*;
pub use self::object::*;
pub use self::pydebug::*;
#[cfg(all(Py_3_8, not(PyPy)))]
pub use self::pylifecycle::*;
File renamed without changes.
2 changes: 0 additions & 2 deletions src/ffi/datetime.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg_attr(feature = "cargo-clippy", allow(clippy::type_complexity))]

//! FFI bindings to the functions and structs defined in `datetime.h`
//!
//! This is the unsafe thin wrapper around the [CPython C API](https://docs.python.org/3/c-api/datetime.html),
Expand Down
6 changes: 3 additions & 3 deletions src/ffi/longobject.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::ffi::object::*;
use crate::ffi::pyport::Py_ssize_t;
use libc::size_t;
use std::os::raw::{
c_char, c_double, c_int, c_long, c_longlong, c_uchar, c_ulong, c_ulonglong, c_void,
};
#[cfg(not(Py_LIMITED_API))]
use std::os::raw::c_uchar;
use std::os::raw::{c_char, c_double, c_int, c_long, c_longlong, c_ulong, c_ulonglong, c_void};

opaque_struct!(PyLongObject);

Expand Down
13 changes: 8 additions & 5 deletions src/ffi/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)]
#![cfg_attr(Py_LIMITED_API, allow(unused_imports))]
#![cfg_attr(feature = "cargo-clippy", allow(clippy::inline_always))]
//! Raw ffi declarations for the C interface of Python.
#![allow(
non_camel_case_types,
non_snake_case,
non_upper_case_globals,
clippy::upper_case_acronyms,
clippy::missing_safety_doc
)]

// Until `extern type` is stabilized, use the recommended approach to
// model opaque types:
Expand Down Expand Up @@ -50,7 +55,6 @@ pub use self::objimpl::*;
pub use self::osmodule::*;
pub use self::pyarena::*;
pub use self::pycapsule::*;
pub use self::pydebug::*;
pub use self::pyerrors::*;
pub use self::pyframe::*;
pub use self::pyhash::*;
Expand Down Expand Up @@ -163,7 +167,6 @@ mod pyport;
// mod pytime; contains nothing of interest

mod objimpl;
mod pydebug;
mod pyhash;
mod pymem;
mod typeslots;
Expand Down
6 changes: 3 additions & 3 deletions src/ffi/pythonrun.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::ffi::object::*;
#[cfg(not(Py_LIMITED_API))]
use crate::ffi::pyarena::PyArena;
#[cfg(not(Py_LIMITED_API))]
use libc::FILE;
use std::os::raw::{c_char, c_int};
use std::ptr;

// TODO: PyCF_MASK etc. constants

Expand Down Expand Up @@ -162,10 +162,10 @@ extern "C" {
#[cfg(any(not(Py_LIMITED_API), PyPy))]
pub unsafe fn Py_CompileString(string: *const c_char, p: *const c_char, s: c_int) -> *mut PyObject {
#[cfg(not(PyPy))]
return Py_CompileStringExFlags(string, p, s, ptr::null_mut(), -1);
return Py_CompileStringExFlags(string, p, s, std::ptr::null_mut(), -1);

#[cfg(PyPy)]
Py_CompileStringFlags(string, p, s, ptr::null_mut())
Py_CompileStringFlags(string, p, s, std::ptr::null_mut())
}

extern "C" {
Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,6 @@ mod conversions;
pub mod derive_utils;
mod err;
pub mod exceptions;
/// Raw ffi declarations for the c interface of python
#[allow(clippy::upper_case_acronyms)]
#[allow(clippy::missing_safety_doc)]
pub mod ffi;
pub mod freelist;
mod gil;
Expand Down
6 changes: 3 additions & 3 deletions src/types/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
//! For more details about these types, see the [Python
//! documentation](https://docs.python.org/3/library/datetime.html)

#![allow(clippy::too_many_arguments)]

use crate::err::PyResult;
use crate::ffi;
#[cfg(PyPy)]
Expand Down Expand Up @@ -130,6 +128,7 @@ pyobject_native_type!(
);

impl PyDateTime {
#[allow(clippy::clippy::too_many_arguments)]
pub fn new<'p>(
py: Python<'p>,
year: i32,
Expand Down Expand Up @@ -157,9 +156,10 @@ impl PyDateTime {
}
}

#[cfg(not(PyPy))]
/// Alternate constructor that takes a `fold` parameter. A `true` value for this parameter
/// signifies a leap second
#[cfg(not(PyPy))]
#[allow(clippy::clippy::too_many_arguments)]
pub fn new_with_fold<'p>(
py: Python<'p>,
year: i32,
Expand Down
2 changes: 1 addition & 1 deletion src/types/floatob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl IntoPy<PyObject> for f64 {

impl<'source> FromPyObject<'source> for f64 {
// PyFloat_AsDouble returns -1.0 upon failure
#![cfg_attr(feature = "cargo-clippy", allow(clippy::float_cmp))]
#![allow(clippy::float_cmp)]
fn extract(obj: &'source PyAny) -> PyResult<Self> {
let v = unsafe { ffi::PyFloat_AsDouble(obj.as_ptr()) };

Expand Down
2 changes: 0 additions & 2 deletions src/types/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ pyobject_native_var_type!(PyLong, ffi::PyLong_Type, ffi::PyLong_Check);
macro_rules! int_fits_c_long {
($rust_type:ty) => {
impl ToPyObject for $rust_type {
#![cfg_attr(feature = "cargo-clippy", allow(clippy::cast_lossless))]
fn to_object(&self, py: Python) -> PyObject {
unsafe { PyObject::from_owned_ptr(py, ffi::PyLong_FromLong(*self as c_long)) }
}
}
impl IntoPy<PyObject> for $rust_type {
#![cfg_attr(feature = "cargo-clippy", allow(clippy::cast_lossless))]
fn into_py(self, py: Python) -> PyObject {
unsafe { PyObject::from_owned_ptr(py, ffi::PyLong_FromLong(self as c_long)) }
}
Expand Down
1 change: 0 additions & 1 deletion tests/test_datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use pyo3::prelude::*;
use pyo3::types::IntoPyDict;

#[allow(clippy::trivially_copy_pass_by_ref)]
fn _get_subclasses<'p>(
py: &'p Python,
py_type: &str,
Expand Down