MCPcopy Index your code
hub / github.com/encode/django-rest-framework / is_simple_callable

Function is_simple_callable

rest_framework/fields.py:66–89  ·  view source on GitHub ↗

True if the object is a callable that takes no arguments.

(obj)

Source from the content-addressed store, hash-verified

64
65
66def is_simple_callable(obj):
67 """
68 True if the object is a callable that takes no arguments.
69 """
70 if not callable(obj):
71 return False
72
73 # Bail early since we cannot inspect built-in function signatures.
74 if inspect.isbuiltin(obj):
75 raise BuiltinSignatureError(
76 'Built-in function signatures are not inspectable. '
77 'Wrap the function call in a simple, pure Python function.')
78
79 if not (inspect.isfunction(obj) or inspect.ismethod(obj) or isinstance(obj, functools.partial)):
80 return False
81
82 sig = inspect.signature(obj)
83 params = sig.parameters.values()
84 return all(
85 param.kind == param.VAR_POSITIONAL or
86 param.kind == param.VAR_KEYWORD or
87 param.default != param.empty
88 for param in params
89 )
90
91
92def get_attribute(instance, attrs):

Callers 8

test_methodMethod · 0.90
test_functionMethod · 0.90
test_not_callableMethod · 0.90
test_4602_regressionMethod · 0.90
test_builtin_functionMethod · 0.90
test_type_annotationMethod · 0.90
get_attributeMethod · 0.90
get_attributeFunction · 0.85

Calls 1

Tested by 6

test_methodMethod · 0.72
test_functionMethod · 0.72
test_not_callableMethod · 0.72
test_4602_regressionMethod · 0.72
test_builtin_functionMethod · 0.72
test_type_annotationMethod · 0.72