summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaura M?dioni <laura.medioni@logilab.fr>2015-10-27 09:46:52 +0100
committerLaura M?dioni <laura.medioni@logilab.fr>2015-10-27 09:46:52 +0100
commitf17f2d9546c42bbf53bb75a77734df33d0c2e182 (patch)
tree426edd3924fcbf7458bc8bec22ada8e20fbe0f65
parent49b2cf899172af6a58e75547683fa8dc4b5fe6c3 (diff)
downloadpylint-f17f2d9546c42bbf53bb75a77734df33d0c2e182.tar.gz
improve NotChecker
- move reverse_op declaration out of visit_unaryop - build message out of operand, instead of using replace() on node.as_string()
-rw-r--r--pylint/checkers/base.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py
index 75a4d7f..df76c60 100644
--- a/pylint/checkers/base.py
+++ b/pylint/checkers/base.py
@@ -1855,6 +1855,9 @@ class NotChecker(_BasicChecker):
'negation.'),
}
+ reverse_op = {'<': '>=', '<=': '>', '>': '<=', '>=': '<', '==': '!=',
+ '!=': '=='}
+
@check_messages('unneeded-not')
def visit_unaryop(self, node):
if node.op != 'not':
@@ -1865,11 +1868,11 @@ class NotChecker(_BasicChecker):
args=(node.as_string(),
operand.operand.as_string()))
elif isinstance(operand, astroid.Compare):
- operator, _ = operand.ops[0]
- reverse_op = {'<': '>=', '<=': '>', '>': '<=', '>=': '<',
- '==': '!=', '!=': '=='}
- suggestion = node.as_string().replace('not ', '').replace(
- operator, reverse_op[operator])
+ left = operand.left
+ operator, right = operand.ops[0]
+ suggestion = '%s %s %s' % (left.as_string(),
+ self.reverse_op[operator],
+ right.as_string())
self.add_message('unneeded-not', node=node,
args=(node.as_string(), suggestion))