[flake8-logging] .exception() and exc_info= outside exception handlers (LOG004, LOG014) (#15799)

This commit is contained in:
InSync 2025-02-04 15:52:12 +07:00 committed by GitHub
parent 11cfe2ea8a
commit ba02294af3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 720 additions and 15 deletions

View 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("")

View file

@ -0,0 +1,4 @@
_ = (logger := __import__("somewhere").logger)
logger.exception("")

View 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)

View file

@ -0,0 +1,4 @@
_ = (logger := __import__("somewhere").logger)
logger.info("", exc_info=True)