Renamed django.utils.inspect.func_has_no_args() to method_has_no_args().

This commit is contained in:
Josh Schneier 2018-08-06 23:12:51 -04:00 committed by Tim Graham
parent 155b31d4ec
commit 756b859576
3 changed files with 10 additions and 5 deletions

View File

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

View File

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

View File

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