summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2022-04-23 12:51:08 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2022-05-02 16:43:54 +0200
commit8a356abf9fe97cc740796ad546e84385814c2a73 (patch)
tree2094f2a4ef4aefddbe825540e8c790c4589f483d
parent2fc25b744a849de293902cb7e899c5975504842d (diff)
downloadpylint-git-8a356abf9fe97cc740796ad546e84385814c2a73.tar.gz
Prepare the functional test for #6444
And small refactor to the code
-rw-r--r--pylint/checkers/strings.py13
-rw-r--r--tests/functional/i/implicit/implicit_str_concat.py4
-rw-r--r--tests/functional/i/implicit/implicit_str_concat.txt2
3 files changed, 10 insertions, 9 deletions
diff --git a/pylint/checkers/strings.py b/pylint/checkers/strings.py
index 8d885756c..e7f14e20b 100644
--- a/pylint/checkers/strings.py
+++ b/pylint/checkers/strings.py
@@ -701,11 +701,11 @@ class StringConstantChecker(BaseTokenChecker, BaseRawFileChecker):
def process_tokens(self, tokens: list[tokenize.TokenInfo]) -> None:
encoding = "ascii"
- for i, (tok_type, token, start, _, line) in enumerate(tokens):
- if tok_type == tokenize.ENCODING:
+ for i, (token_type, token, start, _, line) in enumerate(tokens):
+ if token_type == tokenize.ENCODING:
# this is always the first token processed
encoding = token
- elif tok_type == tokenize.STRING:
+ elif token_type == tokenize.STRING:
# 'token' is the whole un-parsed token; we can look at the start
# of it to see whether it's a raw or unicode string etc.
self.process_string_token(token, start[0], start[1])
@@ -792,13 +792,12 @@ class StringConstantChecker(BaseTokenChecker, BaseRawFileChecker):
if elt.col_offset < 0:
# This can happen in case of escaped newlines
continue
- if (elt.lineno, elt.col_offset) not in self.string_tokens:
+ token_index = (elt.lineno, elt.col_offset)
+ if token_index not in self.string_tokens:
# This may happen with Latin1 encoding
# cf. https://github.com/PyCQA/pylint/issues/2610
continue
- matching_token, next_token = self.string_tokens[
- (elt.lineno, elt.col_offset)
- ]
+ matching_token, next_token = self.string_tokens[token_index]
# We detect string concatenation: the AST Const is the
# combination of 2 string tokens
if matching_token != elt.value and next_token is not None:
diff --git a/tests/functional/i/implicit/implicit_str_concat.py b/tests/functional/i/implicit/implicit_str_concat.py
index 9df3d406a..920b29258 100644
--- a/tests/functional/i/implicit/implicit_str_concat.py
+++ b/tests/functional/i/implicit/implicit_str_concat.py
@@ -30,9 +30,11 @@ TEST_LIST7 = ('a' 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb \
# No warning for bytes
TEST_LIST8 = [b'A' b'B']
+# There's an internal juxtaposition on the second line in a valid multiline
+# TODO #6444: raise implicit-str-concat on the second line pylint: disable=fixme
print(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit,"
- " sed do eiusmod tempor incididunt ut labore et dolore "
+ " sed do eiusmod tempor " "incididunt ut labore et dolore "
"magna aliqua. Ut enim ad minim veniam, quis nostrud "
"exercitation ullamco laboris nisi ut aliquip ex ea "
)
diff --git a/tests/functional/i/implicit/implicit_str_concat.txt b/tests/functional/i/implicit/implicit_str_concat.txt
index d585a68c5..9ab1d416a 100644
--- a/tests/functional/i/implicit/implicit_str_concat.txt
+++ b/tests/functional/i/implicit/implicit_str_concat.txt
@@ -5,4 +5,4 @@ implicit-str-concat:11:0:None:None::Implicit string concatenation found in list:
implicit-str-concat:13:0:None:None::Implicit string concatenation found in call:HIGH
implicit-str-concat:14:0:None:None::Implicit string concatenation found in call:HIGH
implicit-str-concat:27:0:None:None::Implicit string concatenation found in assignment:HIGH
-implicit-str-concat:40:0:None:None::Implicit string concatenation found in call:HIGH
+implicit-str-concat:42:0:None:None::Implicit string concatenation found in call:HIGH