mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-27 08:29:59 +03:00
improve performance for noncallble attributes
This commit is contained in:
parent
e5fb9af0ea
commit
6e26e4ba15
|
@ -63,6 +63,9 @@ def is_simple_callable(obj):
|
||||||
"""
|
"""
|
||||||
True if the object is a callable that takes no arguments.
|
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.
|
# Bail early since we cannot inspect built-in function signatures.
|
||||||
if inspect.isbuiltin(obj):
|
if inspect.isbuiltin(obj):
|
||||||
raise BuiltinSignatureError(
|
raise BuiltinSignatureError(
|
||||||
|
|
|
@ -73,6 +73,10 @@ class TestIsSimpleCallable:
|
||||||
assert is_simple_callable(valid_vargs_kwargs)
|
assert is_simple_callable(valid_vargs_kwargs)
|
||||||
assert not is_simple_callable(invalid)
|
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):
|
def test_4602_regression(self):
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user