summaryrefslogtreecommitdiff
path: root/pylint
diff options
context:
space:
mode:
authorYilei "Dolee" Yang <yileiyang@google.com>2023-04-07 00:06:54 -0700
committerGitHub <noreply@github.com>2023-04-07 09:06:54 +0200
commiteeddd667a6e73ef58fb47cdda154c1751f0ffe71 (patch)
tree64faa879c44721b2e5a1ddf5319a1c513b34de8e /pylint
parent156da64d0fb4c06e15c5b619b91ce550d594a770 (diff)
downloadpylint-git-eeddd667a6e73ef58fb47cdda154c1751f0ffe71.tar.gz
Do not emit `logging-not-lazy` for explicitly concatenated strings. (#8546)
Diffstat (limited to 'pylint')
-rw-r--r--pylint/checkers/logging.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/pylint/checkers/logging.py b/pylint/checkers/logging.py
index 73b44558c..e5fb1ae09 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)