Fix and/or mute more clippy lints, deprecation warnings in Pyo3 (#2805)

This commit is contained in:
Dominik Maier 2025-01-03 15:17:46 +01:00 committed by GitHub
parent 7543a54d0d
commit d39ded5b29
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 8 deletions

View File

@ -357,6 +357,8 @@ mod tests {
tree::{Tree, TreeLike}, tree::{Tree, TreeLike},
}; };
// Some (but not all) versions of clippy think the from_nt things are format strings.
#[allow(clippy::literal_string_with_formatting_args)]
#[test] #[test]
fn simple_context() { fn simple_context() {
let mut ctx = Context::new(); let mut ctx = Context::new();

View File

@ -1,4 +1,6 @@
use std::{string::String, vec::Vec}; #![allow(clippy::useless_conversion)] // This seems to be a false-positive(?)
use std::{ffi::CString, string::String, vec::Vec};
use pyo3::{prelude::*, pyclass, types::IntoPyDict}; use pyo3::{prelude::*, pyclass, types::IntoPyDict};
@ -48,8 +50,8 @@ impl PyContext {
fn loader(py: Python, grammar: &str) -> PyResult<Context> { fn loader(py: Python, grammar: &str) -> PyResult<Context> {
let py_ctx = Bound::new(py, PyContext::new())?; let py_ctx = Bound::new(py, PyContext::new())?;
let locals = [("ctx", &py_ctx)].into_py_dict_bound(py); let locals = [("ctx", &py_ctx)].into_py_dict(py)?;
py.run_bound(grammar, None, Some(&locals))?; py.run(&CString::new(grammar)?, None, Some(&locals))?;
Ok(py_ctx.borrow().get_context()) Ok(py_ctx.borrow().get_context())
} }

View File

@ -85,13 +85,13 @@ impl<'data, 'tree: 'data, 'ctx: 'data, W: Write, T: TreeLike> Unparser<'data, 't
.into_iter() .into_iter()
.map(io::Cursor::into_inner) .map(io::Cursor::into_inner)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let byte_arrays = bufs.iter().map(|b| PyBytes::new_bound(py, b)); let byte_arrays = bufs.iter().map(|b| PyBytes::new(py, b));
let res = expr.call1(py, PyTuple::new_bound(py, byte_arrays))?; let res = expr.call1(py, PyTuple::new(py, byte_arrays)?)?;
let bound = res.bind(py); let bound = res.bind(py);
if PyString::is_type_of_bound(bound) { if PyString::is_type_of(bound) {
let pystr = bound.downcast::<PyString>()?; let pystr = bound.downcast::<PyString>()?;
self.write(pystr.to_string_lossy().as_bytes()); self.write(pystr.to_string_lossy().as_bytes());
} else if PyBytes::is_type_of_bound(bound) { } else if PyBytes::is_type_of(bound) {
let pybytes = bound.downcast::<PyBytes>()?; let pybytes = bound.downcast::<PyBytes>()?;
self.write(pybytes.as_bytes()); self.write(pybytes.as_bytes());
} else { } else {

View File

@ -286,7 +286,9 @@ pub mod pybind {
a6: u64, a6: u64,
a7: u64, a7: u64,
) -> SyscallHookResult { ) -> SyscallHookResult {
unsafe { &*(&raw const PY_SYSCALL_HOOK).as_ref() }.map_or_else( // If we don't deref_addrof we run into the "static-mut-references" lint which is worse.
#[expect(clippy::deref_addrof)]
unsafe { (*(&raw const PY_SYSCALL_HOOK)).as_ref() }.map_or_else(
|| SyscallHookResult::new(None), || SyscallHookResult::new(None),
|obj| { |obj| {
let args = (sys_num, a0, a1, a2, a3, a4, a5, a6, a7); let args = (sys_num, a0, a1, a2, a3, a4, a5, a6, a7);