I have a library module-wrapper that recursively wraps objects. I want to determine if an object has a function-like type. I can check almost all function-like object using:
inspect.isbuiltin(object=obj) or
inspect.isfunction(object=obj) or
inspect.ismethod(object=obj) or
inspect.ismethoddescriptor(object=obj)
The problem is that some bound methods are not detected with this code, for example:
s = "Hello, world!"
type(s.__add__)
# method-wrapper
I guess I cannot check objects for being method-wrapper
using inspect
module. But how do I import this type? I didn't find it.
Now I have an ugly hack in my code:
MethodWrapper = type(''.__add__)
isinstance(obj, MethodWrapper)
UPD0:
I don't want to use callable
because it detects classes and objects, that implement __call__
, but I want those classes and objects to be handled separately.