In my code I need to detect if a variable is a function or not and preform some actions on it.
Everything went well until I now created a partial function using functools and suddenly some of my tests fail:
import types
import functools
def f(s):
print(s)
l = lambda s: print(s)
pf = functools.partial(f, 'Hello World')
pl = functools.partial(l, 'Hello World')
test_f = isinstance(f, types.FunctionType) # True
test_l = isinstance(l, types.FunctionType) # True
test_pf = isinstance(pf, types.FunctionType) # False
test_pl = isinstance(pl, types.FunctionType) # False
Why is there a difference between those? Both varieties are callable... Even more importantly, how can I detect if some variable is a function or not even when it's a partial function if I can't use types.FunctionType?