diff --git a/django/contrib/admindocs/views.py b/django/contrib/admindocs/views.py index ac7cd11f1f..a8875a9747 100644 --- a/django/contrib/admindocs/views.py +++ b/django/contrib/admindocs/views.py @@ -17,8 +17,8 @@ from django.template.engine import Engine from django.urls import get_mod_func, get_resolver, get_urlconf, reverse from django.utils.decorators import method_decorator from django.utils.inspect import ( - func_accepts_kwargs, func_accepts_var_args, func_has_no_args, - get_func_full_args, + func_accepts_kwargs, func_accepts_var_args, get_func_full_args, + method_has_no_args, ) from django.utils.translation import gettext as _ from django.views.generic import TemplateView @@ -275,7 +275,7 @@ class ModelDetailView(BaseAdminDocsView): 'data_type': get_return_data_type(func_name), 'verbose': verbose or '' }) - elif func_has_no_args(func) and not func_accepts_kwargs(func) and not func_accepts_var_args(func): + elif method_has_no_args(func) and not func_accepts_kwargs(func) and not func_accepts_var_args(func): fields.append({ 'name': func_name, 'data_type': get_return_data_type(func_name), diff --git a/django/utils/inspect.py b/django/utils/inspect.py index 355cac48f3..15cd7fbc45 100644 --- a/django/utils/inspect.py +++ b/django/utils/inspect.py @@ -50,9 +50,10 @@ def func_accepts_var_args(func): ) -def func_has_no_args(func): +def method_has_no_args(meth): + """Return True if a method only accepts 'self'.""" args = [ - p for p in inspect.signature(func).parameters.values() + p for p in inspect.signature(meth).parameters.values() if p.kind == p.POSITIONAL_OR_KEYWORD ] return len(args) == 1 diff --git a/tests/utils_tests/test_inspect.py b/tests/utils_tests/test_inspect.py index 7464a9226d..dce8f95ecf 100644 --- a/tests/utils_tests/test_inspect.py +++ b/tests/utils_tests/test_inspect.py @@ -33,3 +33,7 @@ class TestInspectMethods(unittest.TestCase): def test_func_accepts_var_args_no_var_args(self): self.assertIs(inspect.func_accepts_var_args(Person.one_argument), False) + + def test_method_has_no_args(self): + self.assertIs(inspect.method_has_no_args(Person.no_arguments), True) + self.assertIs(inspect.method_has_no_args(Person.one_argument), False)