diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 8d02b3206..31e5b994c 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -62,6 +62,9 @@ def is_simple_callable(obj): """ True if the object is a callable that takes no arguments. """ + if not callable(obj): + return False + # Bail early since we cannot inspect built-in function signatures. if inspect.isbuiltin(obj): raise BuiltinSignatureError( diff --git a/tests/test_fields.py b/tests/test_fields.py index ec121c822..19f734513 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -75,6 +75,10 @@ class TestIsSimpleCallable: assert is_simple_callable(valid_vargs_kwargs) assert not is_simple_callable(invalid) + @pytest.mark.parametrize('obj', (True, None, "str", b'bytes', 123, 1.23)) + def test_not_callable(self, obj): + assert not is_simple_callable(obj) + def test_4602_regression(self): from django.db import models