all Python 3inspectfunction
inspect.isroutine()
object kind checks
Checks that an object is a function or method of any kind: Python, built-in, bound, and method descriptors.
Syntax
inspect.isroutine(object) -> bool
It is the union of isfunction, ismethod, isbuiltin, ismethoddescriptor and ismethodwrapper, but not callable(): a class and an object with __call__ are callable yet are not routines. The answer for functools.partial changed: before 3.14 isroutine(partial(...)) was False, since 3.14 it is True. If code must run on several versions, check partial explicitly with isinstance.
Examples
import inspect
class A:
def m(self): pass
def __call__(self): pass
print(inspect.isroutine(len), inspect.isroutine(A().m)) # → True True
print(inspect.isroutine(list.append), inspect.isroutine(A)) # → True False
print(inspect.isroutine(A()), callable(A())) # → False True
# Python 3.14+
import functools, inspect
print(inspect.isroutine(functools.partial(print))) # → True — до 3.14 было False
See also
Open in the full glossarydocs.python.orgReport an inaccuracy