[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.
This commit is contained in:
Amethyst Reese
2026-01-05 11:42:47 -08:00
committed by GitHub
parent 60f7ec90ef
commit 12a4ca003f

View File

@@ -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