do not use hasattr to check if a value is callable


ID: python-best-practices/use-callable-not-hasattr

Language: Python

Severity: Notice

Category: Best Practices


Do not make any check using hasattr to check if a function is callable since the object may have redefine __getattr__. Instead, use callable().

Learn More

Non-Compliant Code Examples

hasattr(x, '__call__')  # use callable 

Compliant Code Examples

callable(x) jetbrains

Seamless integrations. Try Datadog Code Analysis