From 02898b13da1f4dbe102020cf38d6a036e69f9c44 Mon Sep 17 00:00:00 2001 From: Alvaro Frias Date: Mon, 24 Nov 2025 22:44:31 -0300 Subject: [PATCH 1/2] fix unsupported logging check Signed-off-by: Alvaro Frias --- pylint/checkers/logging.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pylint/checkers/logging.py b/pylint/checkers/logging.py index 3426abdd67..f1de1c5e61 100644 --- a/pylint/checkers/logging.py +++ b/pylint/checkers/logging.py @@ -355,12 +355,16 @@ def _check_format_string(self, node: nodes.Call, format_arg: Literal[0, 1]) -> N keyword_args_cnt + implicit_pos_args + explicit_pos_args ) except utils.UnsupportedFormatCharacter as ex: - char = format_string[ex.index] - self.add_message( - "logging-unsupported-format", - node=node, - args=(char, ord(char), ex.index), - ) + if num_args > 0: + # Only report unsupported format characters if arguments are provided + # When no arguments are supplied, no formatting is performed + # https://docs.python.org/3/library/logging.html#logging.Logger.debug + char = format_string[ex.index] + self.add_message( + "logging-unsupported-format", + node=node, + args=(char, ord(char), ex.index), + ) return except utils.IncompleteFormatString: self.add_message("logging-format-truncated", node=node) From 00b9d7e9b31ad0da96c96b5b015a872f0567512f Mon Sep 17 00:00:00 2001 From: Alvaro Frias Date: Mon, 24 Nov 2025 22:51:37 -0300 Subject: [PATCH 2/2] Add news fragment for logging-unsupported-format fix Refs #10752 --- doc/whatsnew/fragments/10752.false_positive | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 doc/whatsnew/fragments/10752.false_positive diff --git a/doc/whatsnew/fragments/10752.false_positive b/doc/whatsnew/fragments/10752.false_positive new file mode 100644 index 0000000000..f835d8d7d2 --- /dev/null +++ b/doc/whatsnew/fragments/10752.false_positive @@ -0,0 +1,5 @@ +Fixed false positive for ``logging-unsupported-format`` when no arguments are provided to logging functions. + +According to Python's logging documentation, no formatting is performed when no arguments are supplied, so strings like ``logging.error("%test")`` are valid. + +Closes #10752