CodeQL documentation

Non-callable called

ID: py/call-to-non-callable
Kind: problem
Security severity: 
Severity: error
Precision: high
Tags:
   - quality
   - reliability
   - correctness
Query suites:
   - python-security-and-quality.qls

Click to see the query in the CodeQL repository

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.

The 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. Thus, 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.

Recommendation

Since this problem usually indicates a logical error, it is not possible to give a general recipe for fixing it.

Example

lists are not callable. In this example, an attempt is made to call a list which will fail with a TypeError.

a_list = []
a_list()

References

  • © GitHub, Inc.
  • Terms
  • Privacy
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy