mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-07 13:54:47 +03:00
Merge 14c22bcab3
into 4ff9e96b4c
This commit is contained in:
commit
f9d3fecabd
|
@ -140,6 +140,16 @@ def value_from_object(field, obj):
|
|||
return field.value_from_object(obj)
|
||||
|
||||
|
||||
def getargspec(obj):
|
||||
if not hasattr(inspect, 'signature'): # Python 2.7 - 3.2
|
||||
parameters, _, _, defaults = inspect.getargspec(obj)
|
||||
else: # Python +3.3
|
||||
signature = inspect.signature(obj)
|
||||
parameters = signature.parameters
|
||||
defaults = [i for i in parameters if i.default != inspect._empty]
|
||||
|
||||
return parameters, defaults
|
||||
|
||||
# contrib.postgres only supported from 1.8 onwards.
|
||||
try:
|
||||
from django.contrib.postgres import fields as postgres_fields
|
||||
|
|
|
@ -32,7 +32,8 @@ from django.utils.translation import ugettext_lazy as _
|
|||
|
||||
from rest_framework import ISO_8601
|
||||
from rest_framework.compat import (
|
||||
get_remote_field, unicode_repr, unicode_to_repr, value_from_object
|
||||
get_remote_field, getargspec, unicode_repr, unicode_to_repr,
|
||||
value_from_object
|
||||
)
|
||||
from rest_framework.exceptions import ValidationError
|
||||
from rest_framework.settings import api_settings
|
||||
|
@ -59,8 +60,9 @@ def is_simple_callable(obj):
|
|||
if not (function or method):
|
||||
return False
|
||||
|
||||
args, _, _, defaults = inspect.getargspec(obj)
|
||||
len_args = len(args) if function else len(args) - 1
|
||||
parameters, defaults = getargspec(obj)
|
||||
|
||||
len_args = len(parameters) if function else len(parameters) - 1
|
||||
len_defaults = len(defaults) if defaults else 0
|
||||
return len_args <= len_defaults
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user