Skip to content

Commit 3dd27c9

Browse files
committed
Protect against non-Const nodes in is_complex_format_str
1 parent 0a6f659 commit 3dd27c9

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

pylint/checkers/logging.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,8 @@ def _check_format_string(self, node, format_arg):
288288
# formatting characters - it's used verbatim. Don't check any further.
289289
return
290290
format_string = node.args[format_arg].value
291-
if not isinstance(format_string, str):
292-
# If the log format is constant non-string (e.g. logging.debug(5)),
293-
# ensure there are no arguments.
294-
required_num_args = 0
295-
else:
291+
required_num_args = 0
292+
if isinstance(format_string, str):
296293
try:
297294
if self._format_style == "old":
298295
keyword_args, required_num_args, _, _ = utils.parse_format_string(
@@ -339,7 +336,9 @@ def is_complex_format_str(node):
339336
bool: True if inferred string uses complex formatting, False otherwise
340337
"""
341338
inferred = utils.safe_infer(node)
342-
if inferred is None or not isinstance(inferred.value, str):
339+
if inferred is None or not (
340+
isinstance(inferred, astroid.Const) and isinstance(inferred.value, str)
341+
):
343342
return True
344343
try:
345344
parsed = list(string.Formatter().parse(inferred.value))

0 commit comments

Comments
 (0)