A logging call's % format and its arguments do not fit together
What it finds
logger.info("moved %s to %s", path): logging formats the message with % only when the record is emitted, and a format that does not fit its arguments makes logging print --- Logging error --- with a traceback instead of the message, so the line is lost.
Checked are calls of debug, info, warning, error, critical, exception and log on the name of the logging module, of a variable bound once to logging.getLogger(...), or a name such as logger, log, _logger, _log, LOGGER or LOG, whose message is a string literal and that pass arguments to fill it.
From the rule's source, logging_format_mismatch.rs.
import logging logger = logging.getLogger(__name__)audit = logging.getLogger("audit") def move(src, dst, writer): logger.info("moved %s to %s", src)tx0 reports: the message has 2 conversions, but 1 values are given, so logging prints an error instead of this line audit.warning("copied %s", src, dst)tx0 reports: the message has 1 conversions, but 2 values are given logging.error("%(a)s and %(b)s", src, dst)tx0 reports: the message names its values, so it needs one mapping logger.log(logging.INFO, "%d%%", src) logger.info("moved %s to %s", src, dst) logger.info("100% done") writer.info("%s %s", src) Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/python:logging-format-mismatch" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
# tx0: ignore[tx0/python:logging-format-mismatch] reason="..."tx0 explain tx0/python:logging-format-mismatch shows the same in the terminal. Found a false positive? Report it.