diff options
Diffstat (limited to 'pylint/test/input/func_typecheck_non_callable_call.py')
-rw-r--r-- | pylint/test/input/func_typecheck_non_callable_call.py | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/pylint/test/input/func_typecheck_non_callable_call.py b/pylint/test/input/func_typecheck_non_callable_call.py new file mode 100644 index 0000000..832657d --- /dev/null +++ b/pylint/test/input/func_typecheck_non_callable_call.py @@ -0,0 +1,118 @@ +# pylint: disable=R0903,missing-docstring,no-self-use +""" + 'E1102': ('%s is not callable', + 'Used when an object being called has been infered to a non \ + callable object'), +""" + +__revision__ = None + +__revision__() + +def correct(): + """callable object""" + return 1 + +__revision__ = correct() + +class Correct(object): + """callable object""" + +class MetaCorrect(object): + """callable object""" + def __call__(self): + return self + +INSTANCE = Correct() +CALLABLE_INSTANCE = MetaCorrect() +CORRECT = CALLABLE_INSTANCE() +INCORRECT = INSTANCE() +LIST = [] +INCORRECT = LIST() +DICT = {} +INCORRECT = DICT() +TUPLE = () +INCORRECT = TUPLE() +INT = 1 +INCORRECT = INT() + +# Test calling properties. Pylint can detect when using only the +# getter, but it doesn't infer properly when having a getter +# and a setter. +class MyProperty(property): + """ test subclasses """ + +class PropertyTest(object): + """ class """ + + def __init__(self): + self.attr = 4 + + @property + def test(self): + """ Get the attribute """ + return self.attr + + @test.setter + def test(self, value): + """ Set the attribute """ + self.attr = value + + @MyProperty + def custom(self): + """ Get the attribute """ + return self.attr + + @custom.setter + def custom(self, value): + """ Set the attribute """ + self.attr = value + +PROP = PropertyTest() +PROP.test(40) +PROP.custom() + +# Safe from not-callable when using properties. + +class SafeProperty(object): + @property + def static(self): + return staticmethod + + @property + def klass(self): + return classmethod + + @property + def get_lambda(self): + return lambda: None + + @property + def other_function(self): + def function(arg): + return arg + return function + + @property + def dict_builtin(self): + return dict + + @property + def range_builtin(self): + return range + + @property + def instance(self): + class Empty(object): + def __call__(self): + return 42 + return Empty() + +PROP1 = SafeProperty() +PROP1.static(2) +PROP1.klass(2) +PROP1.get_lambda() +PROP1.other_function(4) +PROP1.dict_builtin() +PROP1.range_builtin(4) +PROP1.instance() |