mirror of
https://github.com/astral-sh/ruff
synced 2026-01-21 05:20:49 -05:00
[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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user