mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
[flake8-logging
] .exception()
and exc_info=
outside exception handlers (LOG004
, LOG014
) (#15799)
This commit is contained in:
parent
11cfe2ea8a
commit
ba02294af3
16 changed files with 720 additions and 15 deletions
49
crates/ruff_linter/resources/test/fixtures/flake8_logging/LOG004_0.py
vendored
Normal file
49
crates/ruff_linter/resources/test/fixtures/flake8_logging/LOG004_0.py
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
from logging import exception as exc
|
||||
import logging
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Tests adapted from:
|
||||
# https://github.com/adamchainz/flake8-logging/blob/dbe88e7/tests/test_flake8_logging.py
|
||||
|
||||
|
||||
### Errors
|
||||
|
||||
logging.exception("")
|
||||
logger.exception("")
|
||||
exc("")
|
||||
|
||||
|
||||
def _():
|
||||
logging.exception("")
|
||||
logger.exception("")
|
||||
exc("")
|
||||
|
||||
|
||||
try:
|
||||
...
|
||||
except ...:
|
||||
def _():
|
||||
logging.exception("")
|
||||
logger.exception("")
|
||||
exc("")
|
||||
|
||||
|
||||
### No errors
|
||||
|
||||
try:
|
||||
...
|
||||
except ...:
|
||||
logging.exception("")
|
||||
logger.exception("")
|
||||
exc("")
|
||||
|
||||
|
||||
def _():
|
||||
try:
|
||||
...
|
||||
except ...:
|
||||
logging.exception("")
|
||||
logger.exception("")
|
||||
exc("")
|
4
crates/ruff_linter/resources/test/fixtures/flake8_logging/LOG004_1.py
vendored
Normal file
4
crates/ruff_linter/resources/test/fixtures/flake8_logging/LOG004_1.py
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
_ = (logger := __import__("somewhere").logger)
|
||||
|
||||
|
||||
logger.exception("")
|
57
crates/ruff_linter/resources/test/fixtures/flake8_logging/LOG014_0.py
vendored
Normal file
57
crates/ruff_linter/resources/test/fixtures/flake8_logging/LOG014_0.py
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
import logging
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Tests adapted from:
|
||||
# https://github.com/adamchainz/flake8-logging/blob/dbe88e7/tests/test_flake8_logging.py
|
||||
|
||||
|
||||
### Errors
|
||||
|
||||
logging.info("", exc_info=True)
|
||||
logger.info("", exc_info=True)
|
||||
|
||||
|
||||
logging.info("", exc_info=1)
|
||||
logger.info("", exc_info=1)
|
||||
|
||||
|
||||
def _():
|
||||
logging.info("", exc_info=True)
|
||||
logger.info("", exc_info=True)
|
||||
|
||||
|
||||
try:
|
||||
...
|
||||
except ...:
|
||||
def _():
|
||||
logging.info("", exc_info=True)
|
||||
logger.info("", exc_info=True)
|
||||
|
||||
|
||||
### No errors
|
||||
|
||||
logging.info("", exc_info=a)
|
||||
logger.info("", exc_info=a)
|
||||
|
||||
logging.info("", exc_info=False)
|
||||
logger.info("", exc_info=False)
|
||||
|
||||
|
||||
try:
|
||||
...
|
||||
except ...:
|
||||
logging.info("", exc_info=True)
|
||||
logger.info("", exc_info=True)
|
||||
|
||||
|
||||
def _():
|
||||
try:
|
||||
...
|
||||
except ...:
|
||||
logging.info("", exc_info=True)
|
||||
logger.info("", exc_info=True)
|
||||
|
||||
|
||||
some_variable_that_ends_with_logger.not_a_recognized_method("", exc_info=True)
|
4
crates/ruff_linter/resources/test/fixtures/flake8_logging/LOG014_1.py
vendored
Normal file
4
crates/ruff_linter/resources/test/fixtures/flake8_logging/LOG014_1.py
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
_ = (logger := __import__("somewhere").logger)
|
||||
|
||||
|
||||
logger.info("", exc_info=True)
|
Loading…
Add table
Add a link
Reference in a new issue