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.

not_callable.py 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # pylint: disable=missing-docstring,no-self-use,too-few-public-methods,wrong-import-position
  2. REVISION = None
  3. REVISION() # [not-callable]
  4. def correct():
  5. return 1
  6. REVISION = correct()
  7. class Correct(object):
  8. """callable object"""
  9. class MetaCorrect(object):
  10. """callable object"""
  11. def __call__(self):
  12. return self
  13. INSTANCE = Correct()
  14. CALLABLE_INSTANCE = MetaCorrect()
  15. CORRECT = CALLABLE_INSTANCE()
  16. INCORRECT = INSTANCE() # [not-callable]
  17. LIST = []
  18. INCORRECT = LIST() # [not-callable]
  19. DICT = {}
  20. INCORRECT = DICT() # [not-callable]
  21. TUPLE = ()
  22. INCORRECT = TUPLE() # [not-callable]
  23. INT = 1
  24. INCORRECT = INT() # [not-callable]
  25. # Test calling properties. Pylint can detect when using only the
  26. # getter, but it doesn't infer properly when having a getter
  27. # and a setter.
  28. class MyProperty(property):
  29. """ test subclasses """
  30. class PropertyTest(object):
  31. """ class """
  32. def __init__(self):
  33. self.attr = 4
  34. @property
  35. def test(self):
  36. """ Get the attribute """
  37. return self.attr
  38. @test.setter
  39. def test(self, value):
  40. """ Set the attribute """
  41. self.attr = value
  42. @MyProperty
  43. def custom(self):
  44. """ Get the attribute """
  45. return self.attr
  46. @custom.setter
  47. def custom(self, value):
  48. """ Set the attribute """
  49. self.attr = value
  50. PROP = PropertyTest()
  51. PROP.test(40) # [not-callable]
  52. PROP.custom() # [not-callable]
  53. # Safe from not-callable when using properties.
  54. class SafeProperty(object):
  55. @property
  56. def static(self):
  57. return staticmethod
  58. @property
  59. def klass(self):
  60. return classmethod
  61. @property
  62. def get_lambda(self):
  63. return lambda: None
  64. @property
  65. def other_function(self):
  66. def function(arg):
  67. return arg
  68. return function
  69. @property
  70. def dict_builtin(self):
  71. return dict
  72. @property
  73. def range_builtin(self):
  74. return range
  75. @property
  76. def instance(self):
  77. class Empty(object):
  78. def __call__(self):
  79. return 42
  80. return Empty()
  81. PROP1 = SafeProperty()
  82. PROP1.static(2)
  83. PROP1.klass(2)
  84. PROP1.get_lambda()
  85. PROP1.other_function(4)
  86. PROP1.dict_builtin()
  87. PROP1.range_builtin(4)
  88. PROP1.instance()
  89. import missing # pylint: disable=import-error
  90. class UnknownBaseCallable(missing.Blah):
  91. pass
  92. UnknownBaseCallable()()