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.

no_self_use.py 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # pylint: disable=R0903,W0232,missing-docstring
  2. """test detection of method which could be a function"""
  3. from __future__ import print_function
  4. class Toto(object):
  5. """bla bal abl"""
  6. def __init__(self):
  7. self.aaa = 2
  8. def regular_method(self):
  9. """this method is a real method since it access to self"""
  10. self.function_method()
  11. def function_method(self): # [no-self-use]
  12. """this method isn' a real method since it doesn't need self"""
  13. print('hello')
  14. class Base(object):
  15. """an abstract class"""
  16. def __init__(self):
  17. self.aaa = 2
  18. def check(self, arg):
  19. """an abstract method, could not be a function"""
  20. raise NotImplementedError
  21. class Sub(Base):
  22. """a concrete class"""
  23. def check(self, arg):
  24. """a concrete method, could not be a function since it need
  25. polymorphism benefits
  26. """
  27. return arg == 0
  28. class Super(object):
  29. """same as before without abstract"""
  30. attr = 1
  31. def method(self):
  32. """regular"""
  33. print(self.attr)
  34. class Sub1(Super):
  35. """override method with need for self"""
  36. def method(self):
  37. """no i can not be a function"""
  38. print(42)
  39. def __len__(self):
  40. """no i can not be a function"""
  41. print(42)
  42. def __cmp__(self, other):
  43. """no i can not be a function"""
  44. print(42)
  45. def __copy__(self):
  46. return 24
  47. def __getstate__(self):
  48. return 42
  49. class Prop(object):
  50. @property
  51. def count(self):
  52. """Don't emit no-self-use for properties.
  53. They can't be functions and they can be part of an
  54. API specification.
  55. """
  56. return 42