diff options
author | Nick Drozd <nicholasdrozd@gmail.com> | 2021-10-25 11:09:15 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-25 18:09:15 +0200 |
commit | 30743e0ffbf149246860a0d7ea4a1324c7a8ec00 (patch) | |
tree | b6dda3fc92e658ac1f9aa71da205f0bcb86c6e7b | |
parent | b6ca3b9d6f7ad42accdf90044628521bd711d1ec (diff) | |
download | pylint-git-30743e0ffbf149246860a0d7ea4a1324c7a8ec00.tar.gz |
Use backticks for any-all suggestion (#5207)
* Use backticks for any-all suggestion
If the suggestion contains a string, then the suggestion's quotes can
get mixed up with the the string's quotes.
-rw-r--r-- | pylint/extensions/for_any_all.py | 2 | ||||
-rw-r--r-- | tests/functional/ext/for_any_all.py | 7 | ||||
-rw-r--r-- | tests/functional/ext/for_any_all.txt | 15 |
3 files changed, 16 insertions, 8 deletions
diff --git a/pylint/extensions/for_any_all.py b/pylint/extensions/for_any_all.py index 9c7274095..2086fa4b1 100644 --- a/pylint/extensions/for_any_all.py +++ b/pylint/extensions/for_any_all.py @@ -17,7 +17,7 @@ class ConsiderUsingAnyOrAllChecker(BaseChecker): name = "consider-using-any-or-all" msgs = { "C0501": ( - "`for` loop could be '%s'", + "`for` loop could be `%s`", "consider-using-any-or-all", "A for loop that checks for a condition and return a bool can be replaced with any or all.", ) diff --git a/tests/functional/ext/for_any_all.py b/tests/functional/ext/for_any_all.py index 674bcf68b..785cefebd 100644 --- a/tests/functional/ext/for_any_all.py +++ b/tests/functional/ext/for_any_all.py @@ -52,3 +52,10 @@ def nested_check(items): return True print(items) return items[3] > 5 + +def words_contains_word(words): + """Return whether words contains 'word'""" + for word in words: # [consider-using-any-or-all] + if word == "word": + return True + return False diff --git a/tests/functional/ext/for_any_all.txt b/tests/functional/ext/for_any_all.txt index f5ed43799..da01f06fd 100644 --- a/tests/functional/ext/for_any_all.txt +++ b/tests/functional/ext/for_any_all.txt @@ -1,7 +1,8 @@ -consider-using-any-or-all:5:4:any_even:`for` loop could be 'any(item % 2 == 0 for item in items)' -consider-using-any-or-all:12:4:all_even:`for` loop could be 'all(item % 2 == 0 for item in items)' -consider-using-any-or-all:19:4:any_uneven:`for` loop could be 'not all(item % 2 == 0 for item in items)' -consider-using-any-or-all:26:4:all_uneven:`for` loop could be 'not any(item % 2 == 0 for item in items)' -consider-using-any-or-all:33:4:is_from_string:`for` loop could be 'any(isinstance(parent, str) for parent in item.parents())' -consider-using-any-or-all:40:4:is_not_from_string:`for` loop could be 'not all(isinstance(parent, str) for parent in item.parents())' -consider-using-any-or-all:49:8:nested_check:`for` loop could be 'not any(item in (1, 2, 3) for item in items)' +consider-using-any-or-all:5:4:any_even:`for` loop could be `any(item % 2 == 0 for item in items)` +consider-using-any-or-all:12:4:all_even:`for` loop could be `all(item % 2 == 0 for item in items)` +consider-using-any-or-all:19:4:any_uneven:`for` loop could be `not all(item % 2 == 0 for item in items)` +consider-using-any-or-all:26:4:all_uneven:`for` loop could be `not any(item % 2 == 0 for item in items)` +consider-using-any-or-all:33:4:is_from_string:`for` loop could be `any(isinstance(parent, str) for parent in item.parents())` +consider-using-any-or-all:40:4:is_not_from_string:`for` loop could be `not all(isinstance(parent, str) for parent in item.parents())` +consider-using-any-or-all:49:8:nested_check:`for` loop could be `not any(item in (1, 2, 3) for item in items)` +consider-using-any-or-all:58:4:words_contains_word:`for` loop could be `any(word == 'word' for word in words)` |