summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Mueller <30130371+cdce8p@users.noreply.github.com>2021-06-02 18:06:32 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-06-10 12:49:20 +0200
commitfd8daeef884fe036ff9041339a3876ed38b99668 (patch)
treed1ba562e24fa058d2910098a9751507774a622ce
parent2090d96c3f7978dbc5517e5c974ad96e44744192 (diff)
downloadpylint-git-fd8daeef884fe036ff9041339a3876ed38b99668.tar.gz
Change to consider-using-tuple
-rw-r--r--ChangeLog4
-rw-r--r--doc/whatsnew/2.9.rst3
-rw-r--r--pylint/checkers/refactoring/refactoring_checker.py16
-rw-r--r--tests/functional/c/consider/consider_using_tuple.py (renamed from tests/functional/c/consider/consider_using_tuple_iterator.py)8
-rw-r--r--tests/functional/c/consider/consider_using_tuple.txt4
-rw-r--r--tests/functional/c/consider/consider_using_tuple_iterator.txt4
-rw-r--r--tests/functional/u/undefined/undefined_loop_variable.py2
7 files changed, 23 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index 1743a1570..7a13bb357 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -139,8 +139,8 @@ modules are added.
Closes #4545
-* New checker ``consider-using-tuple-iterator``. Emitted when iterating over
- an in-place define list or set that can be replace by a tuple.
+* New checker ``consider-using-tuple``. Emitted when an in-place defined
+ list or set can be replaced by a tuple.
What's New in Pylint 2.8.3?
diff --git a/doc/whatsnew/2.9.rst b/doc/whatsnew/2.9.rst
index de62da2b7..59321d8d3 100644
--- a/doc/whatsnew/2.9.rst
+++ b/doc/whatsnew/2.9.rst
@@ -39,7 +39,8 @@ New checkers
* New checker ``await-outside-async``: Emitted when await is used outside an async function.
-* ``consider-using-tuple-iterator``: Emitted when iterating over an in-place define list or set that can be replaced by a tuple.
+* ``consider-using-tuple``: Emitted when an in-place defined list or set can be replaced by a tuple.
+
Other Changes
=============
diff --git a/pylint/checkers/refactoring/refactoring_checker.py b/pylint/checkers/refactoring/refactoring_checker.py
index 8eda6c5a3..5a3e34fb2 100644
--- a/pylint/checkers/refactoring/refactoring_checker.py
+++ b/pylint/checkers/refactoring/refactoring_checker.py
@@ -361,9 +361,9 @@ class RefactoringChecker(checkers.BaseTokenChecker):
"Emitted when dictionary values can be replaced by namedtuples or dataclass instances.",
),
"R1735": (
- "Consider iterating over in-place tuple instead",
- "consider-using-tuple-iterator",
- "Emitted when iterating over an in-place defined list or set that can be replaced by a tuple.",
+ "Consider using an in-place tuple%s",
+ "consider-using-tuple",
+ "Emitted when an in-place defined list or set can be replaced by a tuple.",
),
}
options = (
@@ -556,7 +556,7 @@ class RefactoringChecker(checkers.BaseTokenChecker):
"redefined-argument-from-local",
"too-many-nested-blocks",
"unnecessary-dict-index-lookup",
- "consider-using-tuple-iterator",
+ "consider-using-tuple",
)
def visit_for(self, node):
self._check_nested_blocks(node)
@@ -1358,7 +1358,7 @@ class RefactoringChecker(checkers.BaseTokenChecker):
@utils.check_messages(
"unnecessary-comprehension",
"unnecessary-dict-index-lookup",
- "consider-using-tuple-iterator",
+ "consider-using-tuple",
)
def visit_comprehension(self, node: astroid.Comprehension) -> None:
self._check_unnecessary_comprehension(node)
@@ -1782,7 +1782,11 @@ class RefactoringChecker(checkers.BaseTokenChecker):
if isinstance(node.iter, (astroid.List, astroid.Set)) and not any(
isinstance(item, astroid.Starred) for item in node.iter.elts
):
- self.add_message("consider-using-tuple-iterator", node=node.iter)
+ self.add_message(
+ "consider-using-tuple",
+ node=node.iter,
+ args=(f" instead of {node.iter.__class__.__qualname__.lower()}"),
+ )
@utils.check_messages("consider-using-namedtuple-or-dataclass")
def visit_dict(self, node: astroid.Dict) -> None:
diff --git a/tests/functional/c/consider/consider_using_tuple_iterator.py b/tests/functional/c/consider/consider_using_tuple.py
index 7961475c2..679ef77d2 100644
--- a/tests/functional/c/consider/consider_using_tuple_iterator.py
+++ b/tests/functional/c/consider/consider_using_tuple.py
@@ -6,17 +6,17 @@ for x in var:
pass
for x in (1, 2, 3):
pass
-for x in [1, 2, 3]: # [consider-using-tuple-iterator]
+for x in [1, 2, 3]: # [consider-using-tuple]
pass
(x for x in var)
(x for x in (1, 2, 3))
-(x for x in [1, 2, 3]) # [consider-using-tuple-iterator]
-(x for x in {1, 2, 3}) # [consider-using-tuple-iterator]
+(x for x in [1, 2, 3]) # [consider-using-tuple]
+(x for x in {1, 2, 3}) # [consider-using-tuple]
[x for x in var]
[x for x in (1, 2, 3)]
-[x for x in [1, 2, 3]] # [consider-using-tuple-iterator]
+[x for x in [1, 2, 3]] # [consider-using-tuple]
# list/set can't be replaced if tuple unpacking is used
diff --git a/tests/functional/c/consider/consider_using_tuple.txt b/tests/functional/c/consider/consider_using_tuple.txt
new file mode 100644
index 000000000..df796b683
--- /dev/null
+++ b/tests/functional/c/consider/consider_using_tuple.txt
@@ -0,0 +1,4 @@
+consider-using-tuple:9:9::Consider using an in-place tuple instead of list
+consider-using-tuple:14:12::Consider using an in-place tuple instead of list
+consider-using-tuple:15:12::Consider using an in-place tuple instead of set
+consider-using-tuple:19:12::Consider using an in-place tuple instead of list
diff --git a/tests/functional/c/consider/consider_using_tuple_iterator.txt b/tests/functional/c/consider/consider_using_tuple_iterator.txt
deleted file mode 100644
index ead0ffdf2..000000000
--- a/tests/functional/c/consider/consider_using_tuple_iterator.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-consider-using-tuple-iterator:9:9::Consider iterating over in-place tuple instead
-consider-using-tuple-iterator:14:12::Consider iterating over in-place tuple instead
-consider-using-tuple-iterator:15:12::Consider iterating over in-place tuple instead
-consider-using-tuple-iterator:19:12::Consider iterating over in-place tuple instead
diff --git a/tests/functional/u/undefined/undefined_loop_variable.py b/tests/functional/u/undefined/undefined_loop_variable.py
index aa4dc495a..3df043dbe 100644
--- a/tests/functional/u/undefined/undefined_loop_variable.py
+++ b/tests/functional/u/undefined/undefined_loop_variable.py
@@ -1,4 +1,4 @@
-# pylint: disable=missing-docstring,redefined-builtin,consider-using-tuple-iterator
+# pylint: disable=missing-docstring,redefined-builtin,consider-using-tuple
def do_stuff(some_random_list):
for var in some_random_list: