diff options
Diffstat (limited to 'pylint/test')
-rw-r--r-- | pylint/test/functional/superfluous_parens.py | 2 | ||||
-rw-r--r-- | pylint/test/functional/unneeded_not.py | 41 | ||||
-rw-r--r-- | pylint/test/functional/unneeded_not.txt | 12 |
3 files changed, 54 insertions, 1 deletions
diff --git a/pylint/test/functional/superfluous_parens.py b/pylint/test/functional/superfluous_parens.py index 417163e..13418cd 100644 --- a/pylint/test/functional/superfluous_parens.py +++ b/pylint/test/functional/superfluous_parens.py @@ -1,6 +1,6 @@ """Test the superfluous-parens warning.""" from __future__ import print_function - +# pylint: disable=unneeded-not i = 3 if (i == 5): # [superfluous-parens] pass diff --git a/pylint/test/functional/unneeded_not.py b/pylint/test/functional/unneeded_not.py new file mode 100644 index 0000000..882a238 --- /dev/null +++ b/pylint/test/functional/unneeded_not.py @@ -0,0 +1,41 @@ +"""Check exceeding negations in boolean expressions trigger warnings""" + +# pylint: disable=singleton-comparison + +def unneeded_not(): + """This is not ok + """ + bool_var = True + someint = 2 + if not not bool_var: # [unneeded-not] + pass + if not someint == 1: # [unneeded-not] + pass + if not someint != 1: # [unneeded-not] + pass + if not someint < 1: # [unneeded-not] + pass + if not someint > 1: # [unneeded-not] + pass + if not someint <= 1: # [unneeded-not] + pass + if not someint >= 1: # [unneeded-not] + pass + if not not someint: # [unneeded-not] + pass + if not bool_var == True: # [unneeded-not] + pass + if not bool_var == False: # [unneeded-not] + pass + if not bool_var != True: # [unneeded-not] + pass + if not True == True: # [unneeded-not] + pass + + +def not_checked(): + """This is ok""" + bool_var = True + someint = 2 + if not(bool_var == False and someint == 1): + pass diff --git a/pylint/test/functional/unneeded_not.txt b/pylint/test/functional/unneeded_not.txt new file mode 100644 index 0000000..83100a4 --- /dev/null +++ b/pylint/test/functional/unneeded_not.txt @@ -0,0 +1,12 @@ +unneeded-not:10:unneeded_not:One not too many in "not not bool_var", should be "bool_var" +unneeded-not:12:unneeded_not:One not too many in "not someint == 1", should be "someint != 1" +unneeded-not:14:unneeded_not:One not too many in "not someint != 1", should be "someint == 1" +unneeded-not:16:unneeded_not:One not too many in "not someint < 1", should be "someint >= 1" +unneeded-not:18:unneeded_not:One not too many in "not someint > 1", should be "someint <= 1" +unneeded-not:20:unneeded_not:One not too many in "not someint <= 1", should be "someint > 1" +unneeded-not:22:unneeded_not:One not too many in "not someint >= 1", should be "someint < 1" +unneeded-not:24:unneeded_not:One not too many in "not not someint", should be "someint" +unneeded-not:26:unneeded_not:One not too many in "not bool_var == True", should be "bool_var != True" +unneeded-not:28:unneeded_not:One not too many in "not bool_var == False", should be "bool_var != False" +unneeded-not:30:unneeded_not:One not too many in "not bool_var != True", should be "bool_var == True" +unneeded-not:32:unneeded_not:One not too many in "not True == True", should be "True != True" |