Skip to content

Commit 9b9adca

Browse files
authored
ci: try to clean up some lint allows (#5577)
* ci: try to clean up some lint `allow`s * restore one `dead_code` lint * downgrade one `expect` to `allow` * another one
1 parent 5786143 commit 9b9adca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+152
-133
lines changed

pyo3-benches/benches/bench_frompyobject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use pyo3::{
88
};
99

1010
#[derive(FromPyObject)]
11-
#[allow(dead_code)]
11+
#[expect(dead_code)]
1212
enum ManyTypes {
1313
Int(i32),
1414
Bytes(Vec<u8>),

pyo3-build-config/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// Allow dead code because not all code in the modules is used in this build script.
33

44
#[path = "src/impl_.rs"]
5-
#[allow(dead_code)]
5+
#[allow(dead_code, reason = "not all code is used in build.rs")]
66
mod impl_;
77

88
#[path = "src/errors.rs"]
9-
#[allow(dead_code)]
9+
#[allow(dead_code, reason = "not all code is used in build.rs")]
1010
mod errors;
1111

1212
use std::{env, path::Path};

pyo3-build-config/src/lib.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,10 @@ pub fn get() -> &'static InterpreterConfig {
120120
.map(|path| path.exists())
121121
.unwrap_or(false);
122122

123-
// CONFIG_FILE is generated in build.rs, so its content can vary
124-
#[allow(unknown_lints, clippy::const_is_empty)]
123+
#[allow(
124+
clippy::const_is_empty,
125+
reason = "CONFIG_FILE is generated in build.rs, content can vary"
126+
)]
125127
if let Some(interpreter_config) = InterpreterConfig::from_cargo_dep_env() {
126128
interpreter_config
127129
} else if let Some(interpreter_config) = config_from_pyo3_config_file_env() {
@@ -141,8 +143,10 @@ fn config_from_pyo3_config_file_env() -> Option<InterpreterConfig> {
141143
#[doc(hidden)]
142144
const CONFIG_FILE: &str = include_str!(concat!(env!("OUT_DIR"), "/pyo3-build-config-file.txt"));
143145

144-
// CONFIG_FILE is generated in build.rs, so its content can vary
145-
#[allow(clippy::const_is_empty)]
146+
#[allow(
147+
clippy::const_is_empty,
148+
reason = "CONFIG_FILE is generated in build.rs, content can vary"
149+
)]
146150
if !CONFIG_FILE.is_empty() {
147151
let config = InterpreterConfig::from_reader(Cursor::new(CONFIG_FILE))
148152
.expect("contents of CONFIG_FILE should always be valid (generated by pyo3-build-config's build.rs)");
@@ -265,8 +269,10 @@ pub mod pyo3_build_script_impl {
265269
/// Steps 2 and 3 are necessary because `pyo3-ffi`'s build script is the first code run which knows
266270
/// the correct target triple.
267271
pub fn resolve_build_config(target: &Triple) -> Result<BuildConfig> {
268-
// CONFIG_FILE is generated in build.rs, so it's content can vary
269-
#[allow(unknown_lints, clippy::const_is_empty)]
272+
#[allow(
273+
clippy::const_is_empty,
274+
reason = "CONFIG_FILE is generated in build.rs, content can vary"
275+
)]
270276
if let Some(mut interpreter_config) = config_from_pyo3_config_file_env() {
271277
interpreter_config.apply_default_lib_name_to_config_file(target);
272278
interpreter_config.generate_import_libs()?;

pyo3-ffi/examples/sequential/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ mod id;
66
mod module;
77
use crate::module::MODULE_DEF;
88

9-
// The module initialization function, which must be named `PyInit_<your_module>`.
10-
#[allow(non_snake_case)]
9+
#[allow(non_snake_case, reason = "must be named `PyInit_<your_module>`")]
1110
#[no_mangle]
1211
pub unsafe extern "C" fn PyInit_sequential() -> *mut PyObject {
1312
PyModuleDef_Init(ptr::addr_of_mut!(MODULE_DEF))

pyo3-ffi/examples/string-sum/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ static mut SLOTS: &[PyModuleDef_Slot] = &[
4545
},
4646
];
4747

48-
// The module initialization function, which must be named `PyInit_<your_module>`.
49-
#[allow(non_snake_case)]
48+
// The module initialization function
49+
#[allow(non_snake_case, reason = "must be named `PyInit_<your_module>`")]
5050
#[no_mangle]
5151
pub unsafe extern "C" fn PyInit_string_sum() -> *mut PyObject {
5252
PyModuleDef_Init(ptr::addr_of_mut!(MODULE_DEF))
@@ -69,7 +69,10 @@ unsafe fn parse_arg_as_i32(obj: *mut PyObject, n_arg: usize) -> Option<i32> {
6969
let mut overflow = 0;
7070
let i_long: c_long = PyLong_AsLongAndOverflow(obj, &mut overflow);
7171

72-
#[allow(irrefutable_let_patterns)] // some platforms have c_long equal to i32
72+
#[allow(
73+
irrefutable_let_patterns,
74+
reason = "some platforms have c_long equal to i32"
75+
)]
7376
if overflow != 0 {
7477
raise_overflowerror(obj);
7578
None

pyo3-ffi/src/compat/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ macro_rules! compat_function {
3636
// cfgs line up, then the the two glob imports will resolve to the same item via the
3737
// re-export. If the cfgs mismatch, then the use of $name will be ambiguous in cases
3838
// where the function is defined twice, and the test will fail to compile.
39-
#[allow(unused_imports)]
39+
#[allow(unused_imports, reason = "imports exist to try to trigger name conflicts")]
4040
mod [<test_ $name _export>] {
4141
use $crate::*;
4242
use $crate::compat::*;

pyo3-ffi/src/cpython/genobject.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ pub struct PyGenObject {
1818
pub gi_weakreflist: *mut PyObject,
1919
pub gi_name: *mut PyObject,
2020
pub gi_qualname: *mut PyObject,
21-
#[allow(private_interfaces)]
21+
#[allow(
22+
private_interfaces,
23+
reason = "PyGenObject layout was public until 3.14"
24+
)]
2225
pub gi_exc_state: crate::cpython::pystate::_PyErr_StackItem,
2326
#[cfg(Py_3_11)]
2427
pub gi_origin_or_finalizer: *mut PyObject,

pyo3-ffi/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@
160160
//! PyMethodDef::zeroed(),
161161
//! ];
162162
//!
163-
//! // The module initialization function, which must be named `PyInit_<your_module>`.
164-
//! #[allow(non_snake_case)]
163+
//! // The module initialization function.
164+
//! #[allow(non_snake_case, reason = "must be named `PyInit_<your_module>`")]
165165
//! #[no_mangle]
166166
//! pub unsafe extern "C" fn PyInit_string_sum() -> *mut PyObject {
167167
//! let module = PyModule_Create(ptr::addr_of_mut!(MODULE_DEF));
@@ -195,7 +195,7 @@
195195
//! let mut overflow = 0;
196196
//! let i_long: c_long = PyLong_AsLongAndOverflow(obj, &mut overflow);
197197
//!
198-
//! #[allow(irrefutable_let_patterns)] // some platforms have c_long equal to i32
198+
//! #[allow(irrefutable_let_patterns, reason = "some platforms have c_long equal to i32")]
199199
//! if overflow != 0 {
200200
//! raise_overflowerror(obj);
201201
//! None

pyo3-ffi/src/moduleobject.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ pub struct PyModuleDef_Base {
6060
pub m_copy: *mut PyObject,
6161
}
6262

63-
#[allow(clippy::declare_interior_mutable_const)]
63+
#[allow(
64+
clippy::declare_interior_mutable_const,
65+
reason = "contains atomic refcount on free-threaded builds"
66+
)]
6467
pub const PyModuleDef_HEAD_INIT: PyModuleDef_Base = PyModuleDef_Base {
6568
ob_base: PyObject_HEAD_INIT,
6669
m_init: None,
@@ -94,15 +97,21 @@ pub const Py_mod_gil: c_int = 4;
9497
// skipped private _Py_mod_LAST_SLOT
9598

9699
#[cfg(Py_3_12)]
97-
#[allow(clippy::zero_ptr)] // matches the way that the rest of these constants are defined
100+
#[allow(
101+
clippy::zero_ptr,
102+
reason = "matches the way that the rest of these constants are defined"
103+
)]
98104
pub const Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED: *mut c_void = 0 as *mut c_void;
99105
#[cfg(Py_3_12)]
100106
pub const Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED: *mut c_void = 1 as *mut c_void;
101107
#[cfg(Py_3_12)]
102108
pub const Py_MOD_PER_INTERPRETER_GIL_SUPPORTED: *mut c_void = 2 as *mut c_void;
103109

104110
#[cfg(Py_3_13)]
105-
#[allow(clippy::zero_ptr)] // matches the way that the rest of these constants are defined
111+
#[allow(
112+
clippy::zero_ptr,
113+
reason = "matches the way that the rest of these constants are defined"
114+
)]
106115
pub const Py_MOD_GIL_USED: *mut c_void = 0 as *mut c_void;
107116
#[cfg(Py_3_13)]
108117
pub const Py_MOD_GIL_NOT_USED: *mut c_void = 1 as *mut c_void;

pyo3-ffi/src/object.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ pub struct PyObject {
105105
pub ob_type: *mut PyTypeObject,
106106
}
107107

108-
#[allow(clippy::declare_interior_mutable_const)]
108+
#[allow(
109+
clippy::declare_interior_mutable_const,
110+
reason = "contains atomic refcount on free-threaded builds"
111+
)]
109112
pub const PyObject_HEAD_INIT: PyObject = PyObject {
110113
#[cfg(py_sys_config = "Py_TRACE_REFS")]
111114
_ob_next: std::ptr::null_mut(),

0 commit comments

Comments
 (0)