summaryrefslogtreecommitdiff
path: root/pylint/checkers/logging.py
diff options
context:
space:
mode:
authorSvet <svet@hyperscience.com>2019-02-13 10:59:11 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2019-02-13 09:59:11 +0100
commite4fec97bc5af1d1b5ef87a5a15195307858b10a2 (patch)
tree88e2b553f5a34b12bb0a8bfcb66087db68726687 /pylint/checkers/logging.py
parent7a40b0b6d3113403a266ffef13431cdc8e6a8327 (diff)
downloadpylint-git-e4fec97bc5af1d1b5ef87a5a15195307858b10a2.tar.gz
Fixes for linting of new style logging format. (#2713)
The number of arguments was not handled properly, leading to an always successful check. See new tests for specific cases this fixes.
Diffstat (limited to 'pylint/checkers/logging.py')
-rw-r--r--pylint/checkers/logging.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/pylint/checkers/logging.py b/pylint/checkers/logging.py
index 442cf0ed9..13646cdce 100644
--- a/pylint/checkers/logging.py
+++ b/pylint/checkers/logging.py
@@ -286,8 +286,8 @@ class LoggingChecker(checkers.BaseChecker):
"""
num_args = _count_supplied_tokens(node.args[format_arg + 1 :])
if not num_args:
- # If no args were supplied, then all format strings are valid -
- # don't check any further.
+ # 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
if not isinstance(format_string, str):
@@ -305,12 +305,16 @@ class LoggingChecker(checkers.BaseChecker):
# special keywords - out of scope.
return
elif self._format_style == "new":
- keys, num_args, manual_pos_arg = utils.parse_format_method_string(
+ keyword_arguments, implicit_pos_args, explicit_pos_args = utils.parse_format_method_string(
format_string
)
- kargs = len(set(k for k, l in keys if not isinstance(k, int)))
- required_num_args = kargs + num_args + manual_pos_arg
+ keyword_args_cnt = len(
+ set(k for k, l in keyword_arguments if not isinstance(k, int))
+ )
+ required_num_args = (
+ keyword_args_cnt + implicit_pos_args + explicit_pos_args
+ )
except utils.UnsupportedFormatCharacter as ex:
char = format_string[ex.index]
self.add_message(