mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-10 07:14:48 +03:00
Add py3k compatibility to is_simple_callable
This commit is contained in:
parent
7ab4a587d9
commit
a0a8b9890a
|
@ -49,20 +49,34 @@ class empty:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def is_simple_callable(obj):
|
if six.PY3:
|
||||||
"""
|
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.
|
||||||
function = inspect.isfunction(obj)
|
"""
|
||||||
method = inspect.ismethod(obj)
|
if not callable(obj):
|
||||||
|
return False
|
||||||
|
|
||||||
if not (function or method):
|
sig = inspect.signature(obj)
|
||||||
return False
|
params = sig.parameters.values()
|
||||||
|
return all(param.default != param.empty for param in params)
|
||||||
|
|
||||||
args, _, _, defaults = inspect.getargspec(obj)
|
else:
|
||||||
len_args = len(args) if function else len(args) - 1
|
def is_simple_callable(obj):
|
||||||
len_defaults = len(defaults) if defaults else 0
|
function = inspect.isfunction(obj)
|
||||||
return len_args <= len_defaults
|
method = inspect.ismethod(obj)
|
||||||
|
|
||||||
|
if not (function or method):
|
||||||
|
return False
|
||||||
|
|
||||||
|
if method:
|
||||||
|
is_unbound = obj.im_self is None
|
||||||
|
|
||||||
|
args, _, _, defaults = inspect.getargspec(obj)
|
||||||
|
|
||||||
|
len_args = len(args) if function or is_unbound else len(args) - 1
|
||||||
|
len_defaults = len(defaults) if defaults else 0
|
||||||
|
return len_args <= len_defaults
|
||||||
|
|
||||||
|
|
||||||
def get_attribute(instance, attrs):
|
def get_attribute(instance, attrs):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user