From 12a4ca003fb89e4ca079d1922375d17e7225877d Mon Sep 17 00:00:00 2001 From: Amethyst Reese Date: Mon, 5 Jan 2026 11:42:47 -0800 Subject: [PATCH] [`flake8_print`] better suggestion for basicConfig in `T201` docs (#22101) `logging.basicConfig` should not be called at a global module scope, as that produces a race condition to configure logging based on which module gets imported first. Logging should instead be initialized in an entrypoint to the program, either in a `main()` or in the typical `if __name__ == "__main__"` block. --- .../ruff_linter/src/rules/flake8_print/rules/print_call.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/ruff_linter/src/rules/flake8_print/rules/print_call.rs b/crates/ruff_linter/src/rules/flake8_print/rules/print_call.rs index 0c6d023fa4..7514b0b298 100644 --- a/crates/ruff_linter/src/rules/flake8_print/rules/print_call.rs +++ b/crates/ruff_linter/src/rules/flake8_print/rules/print_call.rs @@ -36,13 +36,16 @@ use crate::{Fix, FixAvailability, Violation}; /// ```python /// import logging /// -/// logging.basicConfig(level=logging.INFO) /// logger = logging.getLogger(__name__) /// /// /// def sum_less_than_four(a, b): /// logger.debug("Calling sum_less_than_four") /// return a + b < 4 +/// +/// +/// if __name__ == "__main__": +/// logging.basicConfig(level=logging.INFO) /// ``` /// /// ## Fix safety