mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-05 04:50:12 +03:00
Call any zero-argument callable when accessing attributes
Previously attributes would be explicitly checked using inspect.isfunction/inspect.ismethod, which would miss some callables (e.g. functions implemented in C).
This commit is contained in:
parent
67f382394b
commit
db14d301e9
|
@ -56,7 +56,7 @@ if six.PY3:
|
||||||
"""
|
"""
|
||||||
True if the object is a callable that takes no arguments.
|
True if the object is a callable that takes no arguments.
|
||||||
"""
|
"""
|
||||||
if not (inspect.isfunction(obj) or inspect.ismethod(obj)):
|
if not callable(obj):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
sig = inspect.signature(obj)
|
sig = inspect.signature(obj)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
import functools
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import unittest
|
import unittest
|
||||||
|
@ -68,12 +69,17 @@ class TestIsSimpleCallable:
|
||||||
def valid_vargs_kwargs(*args, **kwargs):
|
def valid_vargs_kwargs(*args, **kwargs):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@functools.lru_cache(None)
|
||||||
|
def wrapped_by_native_function():
|
||||||
|
pass
|
||||||
|
|
||||||
def invalid(param, param2='value'):
|
def invalid(param, param2='value'):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
assert is_simple_callable(simple)
|
assert is_simple_callable(simple)
|
||||||
assert is_simple_callable(valid)
|
assert is_simple_callable(valid)
|
||||||
assert is_simple_callable(valid_vargs_kwargs)
|
assert is_simple_callable(valid_vargs_kwargs)
|
||||||
|
assert is_simple_callable(wrapped_by_native_function)
|
||||||
assert not is_simple_callable(invalid)
|
assert not is_simple_callable(invalid)
|
||||||
|
|
||||||
def test_4602_regression(self):
|
def test_4602_regression(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user