Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add detection for missing logging format arguments (#9999) #10128

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/whatsnew/fragments/9999.false_negative.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add your info here
4 changes: 2 additions & 2 deletions pylint/checkers/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,12 @@ def _check_format_string(self, node: nodes.Call, format_arg: Literal[0, 1]) -> N
format_arg: Index of the format string in the node arguments.
"""
num_args = _count_supplied_tokens(node.args[format_arg + 1 :])
if not num_args:
format_string = node.args[format_arg].value
if not num_args and "%" not in format_string:
# If no args were supplied the string is not interpolated and can contain
# formatting characters - it's used verbatim. Don't check any further.
return

format_string = node.args[format_arg].value
required_num_args = 0
if isinstance(format_string, bytes):
format_string = format_string.decode()
Expand Down
7 changes: 7 additions & 0 deletions tests/functional/l/logging/logging_too_few_args_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Tests for logging-too-few-args when static placeholders are present."""

import logging

logging.error("foo %s") # [logging-too-few-args]
logging.info("Process %s started with ID %d") # [logging-too-few-args]
logging.debug("Missing args: %s %s") # [logging-too-few-args]
2 changes: 2 additions & 0 deletions tests/functional/l/logging/logging_too_few_args_static.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[LOGGING]
logging-format-style=new
Loading