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.

misplaced_comparison_constant.py 1003B

123456789101112131415161718192021222324252627282930313233343536
  1. """Check that the constants are on the right side of the comparisons"""
  2. # pylint: disable=singleton-comparison, missing-docstring, too-few-public-methods
  3. class MyClass(object):
  4. def __init__(self):
  5. self.attr = 1
  6. def dummy_return(self):
  7. return self.attr
  8. def dummy_return():
  9. return 2
  10. def bad_comparisons():
  11. """this is not ok"""
  12. instance = MyClass()
  13. for i in range(10):
  14. if 5 <= i: # [misplaced-comparison-constant]
  15. pass
  16. if 1 == i: # [misplaced-comparison-constant]
  17. pass
  18. if 3 < dummy_return(): # [misplaced-comparison-constant]
  19. pass
  20. if 4 != instance.dummy_return(): # [misplaced-comparison-constant]
  21. pass
  22. if 1 == instance.attr: # [misplaced-comparison-constant]
  23. pass
  24. if "aaa" == instance.attr: # [misplaced-comparison-constant]
  25. pass
  26. def good_comparison():
  27. """this is ok"""
  28. for i in range(10):
  29. if i == 5:
  30. pass