diff options
author | Yilei "Dolee" Yang <yileiyang@google.com> | 2023-04-07 00:06:54 -0700 |
---|---|---|
committer | Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com> | 2023-04-07 09:31:39 +0200 |
commit | 011c6ac1a4efa41ce82fb230ca06f97ae50d662e (patch) | |
tree | e29b38f941f90ce535b15cf61320843d02c7e7c4 /pylint | |
parent | 84d495968cebf368c69932f538ba8d7d2f0bdbd9 (diff) | |
download | pylint-git-011c6ac1a4efa41ce82fb230ca06f97ae50d662e.tar.gz |
Do not emit `logging-not-lazy` for explicitly concatenated strings. (#8546)
(cherry picked from commit eeddd667a6e73ef58fb47cdda154c1751f0ffe71)
Diffstat (limited to 'pylint')
-rw-r--r-- | pylint/checkers/logging.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/pylint/checkers/logging.py b/pylint/checkers/logging.py index f7568a3a4..3064dc926 100644 --- a/pylint/checkers/logging.py +++ b/pylint/checkers/logging.py @@ -246,7 +246,7 @@ class LoggingChecker(checkers.BaseChecker): if isinstance(format_arg, nodes.BinOp): binop = format_arg emit = binop.op == "%" - if binop.op == "+": + if binop.op == "+" and not self._is_node_explicit_str_concatenation(binop): total_number_of_strings = sum( 1 for operand in (binop.left, binop.right) @@ -294,6 +294,19 @@ class LoggingChecker(checkers.BaseChecker): """Return True if the operand in argument is a literal string.""" return isinstance(operand, nodes.Const) and operand.name == "str" + @staticmethod + def _is_node_explicit_str_concatenation(node: nodes.NodeNG) -> bool: + """Return True if the node represents an explicitly concatenated string.""" + if not isinstance(node, nodes.BinOp): + return False + return ( + LoggingChecker._is_operand_literal_str(node.left) + or LoggingChecker._is_node_explicit_str_concatenation(node.left) + ) and ( + LoggingChecker._is_operand_literal_str(node.right) + or LoggingChecker._is_node_explicit_str_concatenation(node.right) + ) + def _check_call_func(self, node: nodes.Call) -> None: """Checks that function call is not format_string.format().""" func = utils.safe_infer(node.func) |