From 9f89f5693aa6066e61a4232aac2fe79aae5f1966 Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Thu, 5 Apr 2018 07:45:47 +0200 Subject: [PATCH] `logging-format-interpolation` also emits when f-strings are used instead of % syntax. Close #1788 --- ChangeLog | 4 ++++ pylint/checkers/logging.py | 2 ++ pylint/test/functional/logging_format_interpolation.py | 1 + pylint/test/functional/logging_format_interpolation.txt | 1 + 4 files changed, 8 insertions(+) diff --git a/ChangeLog b/ChangeLog index 8874c07ee9..db79134925 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/pylint/checkers/logging.py b/pylint/checkers/logging.py index a76e1c1267..73e0a5e3fb 100644 --- a/pylint/checkers/logging.py +++ b/pylint/checkers/logging.py @@ -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): diff --git a/pylint/test/functional/logging_format_interpolation.py b/pylint/test/functional/logging_format_interpolation.py index cbfe87e178..26d375f7ec 100644 --- a/pylint/test/functional/logging_format_interpolation.py +++ b/pylint/test/functional/logging_format_interpolation.py @@ -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')) diff --git a/pylint/test/functional/logging_format_interpolation.txt b/pylint/test/functional/logging_format_interpolation.txt index 36051253c9..6a1ca8ae7c 100644 --- a/pylint/test/functional/logging_format_interpolation.txt +++ b/pylint/test/functional/logging_format_interpolation.txt @@ -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