diff --git a/django/utils/inspect.py b/django/utils/inspect.py index 81a15ed2db66..4e065f0347c1 100644 --- a/django/utils/inspect.py +++ b/django/utils/inspect.py @@ -68,9 +68,7 @@ def func_accepts_var_args(func): def method_has_no_args(meth): """Return True if a method only accepts 'self'.""" - count = len( - [p for p in _get_callable_parameters(meth) if p.kind == p.POSITIONAL_OR_KEYWORD] - ) + count = len([p for p in _get_callable_parameters(meth) if p.kind in ARG_KINDS]) return count == 0 if inspect.ismethod(meth) else count == 1 diff --git a/tests/admin_docs/models.py b/tests/admin_docs/models.py index a403259c6d49..b4ef84cabae4 100644 --- a/tests/admin_docs/models.py +++ b/tests/admin_docs/models.py @@ -54,6 +54,12 @@ def rename_company(self, new_name): def dummy_function(self, baz, rox, *some_args, **some_kwargs): return some_kwargs + def dummy_function_keyword_only_arg(self, *, keyword_only_arg): + return keyword_only_arg + + def all_kinds_arg_function(self, position_only_arg, /, arg, *, kwarg): + return position_only_arg, arg, kwarg + @property def a_property(self): return "a_property" diff --git a/tests/admin_docs/test_views.py b/tests/admin_docs/test_views.py index ef7fde1bf943..064ce27fb0b1 100644 --- a/tests/admin_docs/test_views.py +++ b/tests/admin_docs/test_views.py @@ -280,6 +280,8 @@ def test_methods_with_arguments(self): self.assertContains(self.response, "

Methods with arguments

") self.assertContains(self.response, "rename_company") self.assertContains(self.response, "dummy_function") + self.assertContains(self.response, "dummy_function_keyword_only_arg") + self.assertContains(self.response, "all_kinds_arg_function") self.assertContains(self.response, "suffix_company_name") def test_methods_with_arguments_display_arguments(self): @@ -287,6 +289,7 @@ def test_methods_with_arguments_display_arguments(self): Methods with arguments should have their arguments displayed. """ self.assertContains(self.response, "new_name") + self.assertContains(self.response, "keyword_only_arg") def test_methods_with_arguments_display_arguments_default_value(self): """ @@ -302,6 +305,7 @@ def test_methods_with_multiple_arguments_display_arguments(self): self.assertContains( self.response, "baz, rox, *some_args, **some_kwargs" ) + self.assertContains(self.response, "position_only_arg, arg, kwarg") def test_instance_of_property_methods_are_displayed(self): """Model properties are displayed as fields."""