From 34fd44eb55e2044e655a288fd0b773986435f4f2 Mon Sep 17 00:00:00 2001 From: GiGaGon <107241144+MeGaGiGaGon@users.noreply.github.com> Date: Mon, 23 Jun 2025 06:19:23 -0700 Subject: [PATCH] [`flake8-logging`] Add fix safety section to `LOG001` (#18841) Part of #15584 This adds a `Fix safety` section to [direct-logger-instantiation (LOG001)](https://docs.astral.sh/ruff/rules/direct-logger-instantiation/#direct-logger-instantiation-log001). The fix/lint was introduced in #7397 No reasoning is given on the unsafety in the PR/code Unsafe fix demonstration: [playground](https://play.ruff.rs/72e7277e-a9db-4cd9-9afb-2c56ef2db361) ```py import logging logger = logging.Logger(__name__) ``` ## Test Plan N/A, no tests/functionality affected --------- Co-authored-by: Dylan --- .../rules/flake8_logging/rules/direct_logger_instantiation.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/ruff_linter/src/rules/flake8_logging/rules/direct_logger_instantiation.rs b/crates/ruff_linter/src/rules/flake8_logging/rules/direct_logger_instantiation.rs index c3ff9c2f51..501953d980 100644 --- a/crates/ruff_linter/src/rules/flake8_logging/rules/direct_logger_instantiation.rs +++ b/crates/ruff_linter/src/rules/flake8_logging/rules/direct_logger_instantiation.rs @@ -36,6 +36,10 @@ use crate::{Edit, Fix, FixAvailability, Violation}; /// logger = logging.getLogger(__name__) /// ``` /// +/// ## Fix safety +/// This fix is always unsafe, as changing from `Logger` to `getLogger` +/// changes program behavior by will adding the logger to the logging tree. +/// /// [Logger Objects]: https://docs.python.org/3/library/logging.html#logger-objects #[derive(ViolationMetadata)] pub(crate) struct DirectLoggerInstantiation;