Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

unneeded_not.py 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. """Check exceeding negations in boolean expressions trigger warnings"""
  2. # pylint: disable=singleton-comparison,too-many-branches,too-few-public-methods,undefined-variable
  3. # pylint: disable=literal-comparison
  4. def unneeded_not():
  5. """This is not ok
  6. """
  7. bool_var = True
  8. someint = 2
  9. if not not bool_var: # [unneeded-not]
  10. pass
  11. if not someint == 1: # [unneeded-not]
  12. pass
  13. if not someint != 1: # [unneeded-not]
  14. pass
  15. if not someint < 1: # [unneeded-not]
  16. pass
  17. if not someint > 1: # [unneeded-not]
  18. pass
  19. if not someint <= 1: # [unneeded-not]
  20. pass
  21. if not someint >= 1: # [unneeded-not]
  22. pass
  23. if not not someint: # [unneeded-not]
  24. pass
  25. if not bool_var == True: # [unneeded-not]
  26. pass
  27. if not bool_var == False: # [unneeded-not]
  28. pass
  29. if not bool_var != True: # [unneeded-not]
  30. pass
  31. if not True == True: # [unneeded-not]
  32. pass
  33. if not 2 in [3, 4]: # [unneeded-not]
  34. pass
  35. if not someint is 'test': # [unneeded-not]
  36. pass
  37. def tolerated_statements():
  38. """This is ok"""
  39. bool_var = True
  40. someint = 2
  41. if not(bool_var == False and someint == 1):
  42. pass
  43. if 2 not in [3, 4]:
  44. pass
  45. if not someint == bool_var == 2:
  46. pass
  47. if not 2 <= someint < 3 < 4:
  48. pass
  49. if not set('bar') <= set('foobaz'):
  50. pass
  51. if not set(something) <= 3:
  52. pass
  53. if not frozenset(something) <= 3:
  54. pass
  55. class Klass(object):
  56. """This is also ok"""
  57. def __ne__(self, other):
  58. return not self == other