mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-29 17:39:48 +03:00
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:
parent
564faddb0f
commit
5acdf51c7d
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user