mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-11 04:07:39 +03:00
Merge pull request #657 from dgaus/master
Make is_simple_callable consider default arguments
This commit is contained in:
commit
367909e2c2
|
@ -25,10 +25,14 @@ def is_simple_callable(obj):
|
|||
"""
|
||||
True if the object is a callable that takes no arguments.
|
||||
"""
|
||||
return (
|
||||
(inspect.isfunction(obj) and not inspect.getargspec(obj)[0]) or
|
||||
(inspect.ismethod(obj) and len(inspect.getargspec(obj)[0]) <= 1)
|
||||
)
|
||||
try:
|
||||
args, _, _, defaults = inspect.getargspec(obj)
|
||||
except TypeError:
|
||||
return False
|
||||
else:
|
||||
len_args = len(args) if inspect.isfunction(obj) else len(args) - 1
|
||||
len_defaults = len(defaults) if defaults else 0
|
||||
return len_args <= len_defaults
|
||||
|
||||
|
||||
def get_component(obj, attr_name):
|
||||
|
|
Loading…
Reference in New Issue
Block a user