Skip to content

Commit 281fc07

Browse files
KrukovDima Kryukov
andauthored
improve performance for noncallble attributes (#8502)
Co-authored-by: Dima Kryukov <[email protected]>
1 parent 292ead1 commit 281fc07

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

rest_framework/fields.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ def is_simple_callable(obj):
6262
"""
6363
True if the object is a callable that takes no arguments.
6464
"""
65+
if not callable(obj):
66+
return False
67+
6568
# Bail early since we cannot inspect built-in function signatures.
6669
if inspect.isbuiltin(obj):
6770
raise BuiltinSignatureError(

tests/test_fields.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ def invalid(param, param2='value'):
7575
assert is_simple_callable(valid_vargs_kwargs)
7676
assert not is_simple_callable(invalid)
7777

78+
@pytest.mark.parametrize('obj', (True, None, "str", b'bytes', 123, 1.23))
79+
def test_not_callable(self, obj):
80+
assert not is_simple_callable(obj)
81+
7882
def test_4602_regression(self):
7983
from django.db import models
8084

0 commit comments

Comments
 (0)