From 5acdf51c7d735cf83d5184640cc5e483fb18ed69 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 9 May 2019 08:52:23 +0300 Subject: [PATCH] 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. --- rest_framework/fields.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 5e3132074..053c0caff 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -1,7 +1,6 @@ import copy import datetime import decimal -import functools import inspect import re import uuid @@ -53,7 +52,7 @@ def is_simple_callable(obj): """ 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 sig = inspect.signature(obj)