Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.

Metadata

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

Language: Python

Severity: Notice

Category: Best Practices

Description

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)
PREVIEWING: joe.farro/djm/djm-732-rm-dd-api-ips-databricks-docs