summaryrefslogtreecommitdiff
path: root/pylint/checkers/refactoring.py
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2019-06-20 09:23:44 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2019-06-20 09:23:44 +0200
commit8582756731c83142dc8c387de2026edc9bd4969f (patch)
tree53200d51eed9adc057178a4ecdd309fa0a430fa9 /pylint/checkers/refactoring.py
parent5af3758ae0e7377bf8ddde5347f5f456657db6ce (diff)
downloadpylint-git-8582756731c83142dc8c387de2026edc9bd4969f.tar.gz
Ignore ``consider-using-dict-comprehension`` for constructions that can't be converted to a comprehension
Close #2963
Diffstat (limited to 'pylint/checkers/refactoring.py')
-rw-r--r--pylint/checkers/refactoring.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/pylint/checkers/refactoring.py b/pylint/checkers/refactoring.py
index cab521aaa..27a85f563 100644
--- a/pylint/checkers/refactoring.py
+++ b/pylint/checkers/refactoring.py
@@ -237,6 +237,8 @@ class RefactoringChecker(checkers.BaseTokenChecker):
"R1717": (
"Consider using a dictionary comprehension",
"consider-using-dict-comprehension",
+ "Emitted when we detect the creation of a dictionary "
+ "using the dict() callable and a transient list. "
"Although there is nothing syntactically wrong with this code, "
"it is hard to read and can be simplified to a dict comprehension."
"Also it is faster since you don't need to create another "
@@ -617,11 +619,16 @@ class RefactoringChecker(checkers.BaseTokenChecker):
if (
isinstance(node.func, astroid.Name)
and node.args
- and node.func.name in {"dict", "set"}
and isinstance(node.args[0], astroid.ListComp)
):
- message_name = "consider-using-{}-comprehension".format(node.func.name)
- self.add_message(message_name, node=node)
+ if node.func.name == "dict" and not isinstance(
+ node.args[0].elt, astroid.Call
+ ):
+ message_name = "consider-using-dict-comprehension"
+ self.add_message(message_name, node=node)
+ elif node.func.name == "set":
+ message_name = "consider-using-set-comprehension"
+ self.add_message(message_name, node=node)
@utils.check_messages(
"stop-iteration-return",