diff options
| author | Diego Gaustein | 2013-02-13 20:34:23 -0300 |
|---|---|---|
| committer | Diego Gaustein | 2013-02-13 20:34:23 -0300 |
| commit | 40b13a869b0c6bfbacf4498fc834dc9052d8b363 (patch) | |
| tree | 8e03255b8abbbf9c320b79d02d813504ed6cf532 /rest_framework/fields.py | |
| parent | 569dc67a1220f0b577e7873bf7ee3ac54cf60143 (diff) | |
| download | django-rest-framework-40b13a869b0c6bfbacf4498fc834dc9052d8b363.tar.bz2 | |
Make is_simple_callable consider fields which have default arguments
Diffstat (limited to 'rest_framework/fields.py')
| -rw-r--r-- | rest_framework/fields.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 327008fb..abc5fd44 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -24,10 +24,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): |
