summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/utils/inspect.py6
-rw-r--r--tests/utils_tests/test_inspect.py2
2 files changed, 5 insertions, 3 deletions
diff --git a/django/utils/inspect.py b/django/utils/inspect.py
index 15cd7fbc45..293cbdffa1 100644
--- a/django/utils/inspect.py
+++ b/django/utils/inspect.py
@@ -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):
diff --git a/tests/utils_tests/test_inspect.py b/tests/utils_tests/test_inspect.py
index dce8f95ecf..3967f2c886 100644
--- a/tests/utils_tests/test_inspect.py
+++ b/tests/utils_tests/test_inspect.py
@@ -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)