-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow specification of
logging.Logger
re-exports via `logger-object…
…s` (#5750) ## Summary This PR adds a `logger-objects` setting that allows users to mark specific symbols a `logging.Logger` objects. Currently, if a `logger` is imported, we only flagged it as a `logging.Logger` if it comes exactly from the `logging` module or is `flask.current_app.logger`. This PR allows users to mark specific loggers, like `logging_setup.logger`, to ensure that they're covered by the `flake8-logging-format` rules and others. For example, if you have a module `logging_setup.py` with the following contents: ```python import logging logger = logging.getLogger(__name__) ``` Adding `"logging_setup.logger"` to `logger-objects` will ensure that `logging_setup.logger` is treated as a `logging.Logger` object when imported from other modules (e.g., `from logging_setup import logger`). Closes #5694.
- Loading branch information
1 parent
727153c
commit f9726af
Showing
16 changed files
with
200 additions
and
107 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
crates/ruff/resources/test/fixtures/flake8_logging_format/G010.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import logging | ||
from distutils import log | ||
|
||
from logging_setup import logger | ||
|
||
logging.warn("Hello World!") | ||
log.warn("Hello world!") # This shouldn't be considered as a logger candidate | ||
logger.warn("Hello world!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 28 additions & 10 deletions
38
...s/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G010.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,40 @@ | ||
--- | ||
source: crates/ruff/src/rules/flake8_logging_format/mod.rs | ||
--- | ||
G010.py:4:9: G010 [*] Logging statement uses `warn` instead of `warning` | ||
G010.py:6:9: G010 [*] Logging statement uses `warn` instead of `warning` | ||
| | ||
2 | from distutils import log | ||
3 | | ||
4 | logging.warn("Hello World!") | ||
4 | from logging_setup import logger | ||
5 | | ||
6 | logging.warn("Hello World!") | ||
| ^^^^ G010 | ||
5 | log.warn("Hello world!") # This shouldn't be considered as a logger candidate | ||
7 | log.warn("Hello world!") # This shouldn't be considered as a logger candidate | ||
8 | logger.warn("Hello world!") | ||
| | ||
= help: Convert to `warn` | ||
|
||
ℹ Fix | ||
1 1 | import logging | ||
2 2 | from distutils import log | ||
3 3 | | ||
4 |-logging.warn("Hello World!") | ||
4 |+logging.warning("Hello World!") | ||
5 5 | log.warn("Hello world!") # This shouldn't be considered as a logger candidate | ||
4 4 | from logging_setup import logger | ||
5 5 | | ||
6 |-logging.warn("Hello World!") | ||
6 |+logging.warning("Hello World!") | ||
7 7 | log.warn("Hello world!") # This shouldn't be considered as a logger candidate | ||
8 8 | logger.warn("Hello world!") | ||
|
||
G010.py:8:8: G010 [*] Logging statement uses `warn` instead of `warning` | ||
| | ||
6 | logging.warn("Hello World!") | ||
7 | log.warn("Hello world!") # This shouldn't be considered as a logger candidate | ||
8 | logger.warn("Hello world!") | ||
| ^^^^ G010 | ||
| | ||
= help: Convert to `warn` | ||
|
||
ℹ Fix | ||
5 5 | | ||
6 6 | logging.warn("Hello World!") | ||
7 7 | log.warn("Hello world!") # This shouldn't be considered as a logger candidate | ||
8 |-logger.warn("Hello world!") | ||
8 |+logger.warning("Hello world!") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.