From 2c7980b773cad586af5db8ff0755f1d74d94f7d1 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Mon, 14 Oct 2024 18:05:33 +0200 Subject: refactor(treewide): Conform to the clippy and rust lints --- crates/yt_dlp/src/logging.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'crates/yt_dlp/src/logging.rs') diff --git a/crates/yt_dlp/src/logging.rs b/crates/yt_dlp/src/logging.rs index 4039da4..385255d 100644 --- a/crates/yt_dlp/src/logging.rs +++ b/crates/yt_dlp/src/logging.rs @@ -12,6 +12,9 @@ // It is licensed under the Apache 2.0 License, copyright up to 2024 by Dylan Storey // It was modified by Benedikt Peetz 2024 +// The pyo3 `pyfunction` proc-macros call unsafe functions internally, which trigger this lint. +#![allow(unsafe_op_in_unsafe_fn)] + use log::{logger, Level, MetadataBuilder, Record}; use pyo3::{ prelude::{PyAnyMethods, PyListMethods, PyModuleMethods}, @@ -19,6 +22,7 @@ use pyo3::{ }; /// Consume a Python `logging.LogRecord` and emit a Rust `Log` instead. +#[allow(clippy::needless_pass_by_value)] #[pyfunction] fn host_log(record: Bound<'_, PyAny>, rust_target: &str) -> PyResult<()> { let level = record.getattr("levelno")?; @@ -37,7 +41,7 @@ fn host_log(record: Bound<'_, PyAny>, rust_target: &str) -> PyResult<()> { } else { // Libraries (ex: tracing_subscriber::filter::Directive) expect rust-style targets like foo::bar, // and may not deal well with "." as a module separator: - let logger_name = logger_name.replace(".", "::"); + let logger_name = logger_name.replace('.', "::"); Some(format!("{rust_target}::{logger_name}")) }; @@ -84,10 +88,11 @@ fn host_log(record: Bound<'_, PyAny>, rust_target: &str) -> PyResult<()> { Ok(()) } -/// Registers the host_log function in rust as the event handler for Python's logging logger +/// Registers the `host_log` function in rust as the event handler for Python's logging logger /// This function needs to be called from within a pyo3 context as early as possible to ensure logging messages /// arrive to the rust consumer. -pub fn setup_logging(py: Python, target: &str) -> PyResult<()> { +#[allow(clippy::module_name_repetitions)] +pub fn setup_logging(py: Python<'_>, target: &str) -> PyResult<()> { let logging = py.import_bound("logging")?; logging.setattr("host_log", wrap_pyfunction!(host_log, &logging)?)?; @@ -100,15 +105,14 @@ class HostHandler(Handler): super().__init__(level=level) def emit(self, record): - host_log(record,"{}") + host_log(record,"{target}") oldBasicConfig = basicConfig def basicConfig(*pargs, **kwargs): if "handlers" not in kwargs: kwargs["handlers"] = [HostHandler()] return oldBasicConfig(*pargs, **kwargs) -"#, - target +"# ) .as_str(), Some(&logging.dict()), -- cgit 1.4.1