diff options
| author | Tom Christie | 2013-02-15 01:13:14 -0800 | 
|---|---|---|
| committer | Tom Christie | 2013-02-15 01:13:14 -0800 | 
| commit | 367909e2c2162cf37518ac9885950432722567e4 (patch) | |
| tree | caa98223800bf949bbfa14c7437edbfba86b028d /rest_framework | |
| parent | 6dd867c8fe2673d1c57e503c35ca630188e98e19 (diff) | |
| parent | 40b13a869b0c6bfbacf4498fc834dc9052d8b363 (diff) | |
| download | django-rest-framework-367909e2c2162cf37518ac9885950432722567e4.tar.bz2 | |
Merge pull request #657 from dgaus/master
Make is_simple_callable consider default arguments
Diffstat (limited to 'rest_framework')
| -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 236e0f1e..e1fd1b64 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -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):  | 
