diff options
author | Nick Bastin <nick.bastin@gmail.com> | 2015-12-19 10:26:21 -0800 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2015-12-24 15:13:00 +0200 |
commit | 2c80b61b31f35adfc61fd901692fde0ce13cb40e (patch) | |
tree | f7e5dced65aa6d23d983aff98359e28b68e0a233 | |
parent | 9e8e2ae9ad7636af3e81b0418e7de959efcfda94 (diff) | |
download | pylint-git-2c80b61b31f35adfc61fd901692fde0ce13cb40e.tar.gz |
Ignore unneeded-not in __ne__, test it
-rw-r--r-- | pylint/checkers/base.py | 7 | ||||
-rw-r--r-- | pylint/test/functional/unneeded_not.py | 6 |
2 files changed, 13 insertions, 0 deletions
diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py index d9195153c..17faa4829 100644 --- a/pylint/checkers/base.py +++ b/pylint/checkers/base.py @@ -1860,6 +1860,7 @@ class NotChecker(_BasicChecker): if node.op != 'not': return operand = node.operand + if isinstance(operand, astroid.UnaryOp) and operand.op == 'not': self.add_message('unneeded-not', node=node, args=(node.as_string(), @@ -1872,6 +1873,12 @@ class NotChecker(_BasicChecker): operator, right = operand.ops[0] if operator not in self.reverse_op: return + + # Ignore __ne__ as function of __eq__ + frame = node.frame() + if frame.name == '__ne__' and operator == '==': + return + suggestion = '%s %s %s' % (left.as_string(), self.reverse_op[operator], right.as_string()) diff --git a/pylint/test/functional/unneeded_not.py b/pylint/test/functional/unneeded_not.py index 8f7ba935e..06f0b3275 100644 --- a/pylint/test/functional/unneeded_not.py +++ b/pylint/test/functional/unneeded_not.py @@ -49,3 +49,9 @@ def not_checked(): pass if not 2 <= someint < 3 < 4: pass + +class Klass(object): + """This is also ok""" + def __ne__(self, other): + return not self == other + |