Refs #29244 -- Fixed django.utils.inspect.method_has_no_args() for bound methods.
This commit is contained in:
parent
756b859576
commit
f1bf069ec1
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue