Simplify is_simple_callable() and make it faster and more general

This function shows up in some profiles.

callable() is a fast builtin function. It covers the existing checks and
all others as well. inspect.signature() accepts any callable.
This commit is contained in:
Ran Benita 2019-05-09 08:52:23 +03:00
parent 564faddb0f
commit 5acdf51c7d

View File

@ -1,7 +1,6 @@
import copy import copy
import datetime import datetime
import decimal import decimal
import functools
import inspect import inspect
import re import re
import uuid import uuid
@ -53,7 +52,7 @@ def is_simple_callable(obj):
""" """
True if the object is a callable that takes no arguments. True if the object is a callable that takes no arguments.
""" """
if not (inspect.isfunction(obj) or inspect.ismethod(obj) or isinstance(obj, functools.partial)): if not callable(obj):
return False return False
sig = inspect.signature(obj) sig = inspect.signature(obj)