Skip to content

Commit

Permalink
logging-format-interpolation also emits when f-strings are used ins…
Browse files Browse the repository at this point in the history
…tead of % syntax.

Close #1788
  • Loading branch information
PCManticore committed Apr 5, 2018
1 parent 1649334 commit 9f89f56
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Pylint's ChangeLog
What's New in Pylint 2.0?
=========================

* `logging-format-interpolation` also emits when f-strings are used instead of % syntax.

Close #1788

* Add a new check, `possibly-unused-variable`.

This is similar to `unused-variable`, the only difference is that it is
Expand Down
2 changes: 2 additions & 0 deletions pylint/checkers/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ def _check_log_method(self, node, name):
self._check_call_func(node.args[format_pos])
elif isinstance(node.args[format_pos], astroid.Const):
self._check_format_string(node, format_pos)
elif isinstance(node.args[format_pos], astroid.JoinedStr):
self.add_message('logging-format-interpolation', node=node)

@staticmethod
def _is_operand_literal_str(operand):
Expand Down
1 change: 1 addition & 0 deletions pylint/test/functional/logging_format_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
renamed_logging.debug(FORMAT_STR.format(4, 5)) # [logging-format-interpolation]
renamed_logging.log(renamed_logging.DEBUG, FORMAT_STR.format(4, 5)) # [logging-format-interpolation]
renamed_logging.info("Read {l} rows".format(l=123456789)) # [logging-format-interpolation]
renamed_logging.info(f'Read {FORMAT_STR} from globals') # [logging-format-interpolation]

# Statements that should not be flagged:
renamed_logging.debug(format(66, 'x'))
Expand Down
1 change: 1 addition & 0 deletions pylint/test/functional/logging_format_interpolation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ logging-format-interpolation:17::Use % formatting in logging functions and pass
logging-format-interpolation:18::Use % formatting in logging functions and pass the % parameters as arguments
logging-format-interpolation:19::Use % formatting in logging functions and pass the % parameters as arguments
logging-format-interpolation:20::Use % formatting in logging functions and pass the % parameters as arguments
logging-format-interpolation:21::Use % formatting in logging functions and pass the % parameters as arguments

0 comments on commit 9f89f56

Please sign in to comment.