Refs #29244 -- Fixed django.utils.inspect.method_has_no_args() for bound methods.

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

View File

@ -52,11 +52,11 @@ def func_accepts_var_args(func):
def method_has_no_args(meth):
"""Return True if a method only accepts 'self'."""
args = [
count = len([
p for p in inspect.signature(meth).parameters.values()
if p.kind == p.POSITIONAL_OR_KEYWORD
]
return len(args) == 1
])
return count == 0 if inspect.ismethod(meth) else count == 1
def func_supports_parameter(func, parameter):

View File

@ -37,3 +37,5 @@ class TestInspectMethods(unittest.TestCase):
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)
self.assertIs(inspect.method_has_no_args(Person().no_arguments), True)
self.assertIs(inspect.method_has_no_args(Person().one_argument), False)