Callback validation
Validate a callback before passing it to another function.
Python · Function
Tests whether an object appears callable. Classes, functions, and instances with __call__() can return True, but a True result does not guarantee that invocation will succeed.
callable() tests whether an object appears usable with call syntax. Functions and classes qualify, as do instances whose class defines __call__; a positive result does not guarantee that invoking the object will succeed.
callable(object, /)| Name | Type | Description |
|---|---|---|
object | object | The object to test for apparent callability. |
True if object appears callable; otherwise False.
def greet(name):
return f"Hello, {name}"
class Greeter:
def __call__(self, name):
return greet(name)
for item in (greet, Greeter(), 42):
print(callable(item))Checks whether a function, an instance with __call__, or an integer can be invoked.
Validate a callback before passing it to another function.
Distinguish callable strategy objects from ordinary values.
Check dynamically obtained attributes before invoking them.
__call__iter