Use inspect.isroutine() instead of isfunction() and ismethod()