improve performance for noncallble attributes (#8502)

Co-authored-by: Dima Kryukov <dmitry.kryukov@pandadoc.com>
This commit is contained in:
Krukov D 2022-06-06 14:54:57 +03:00 committed by GitHub
parent 292ead1fe0
commit 281fc074ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -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(

View File

@ -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