ID: py/call-to-non-callable Kind: problem Security severity: Severity: error Precision: high Tags: - reliability - correctness - types Query suites: - python-security-and-quality.qls
If an object is called,
obj(), then that object must be a callable or a
TypeError will be raised. A callable object is any object whose class defines the
__call__ special method. Callable objects include functions, methods, classes.
callable(object) builtin function determines if an object is callable or not.
When the Python interpreter attempts to evaluate a call such as
func(arg) it will invoke the
__call__ special method on
func(arg) is roughly equivalent to
type(func).__call__(func, arg) which means that the class must define the attribute
__call__, merely adding it to the instance is not sufficient.
Since this problem usually indicates a logical error, it is not possible to give a general recipe for fixing it.
lists are not callable. In this example, an attempt is made to call a
list which will fail with a
a_list =  a_list()