From 15bae9fb1ed6f3f0f862ad4322ece56e94dcc48e Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Fri, 11 Oct 2019 11:33:33 +0200 Subject: [PATCH] Do not emit ``no-method-argument`` for functions using positional only args. Close #3161 --- ChangeLog | 4 ++++ pylint/checkers/classes.py | 9 +++++++-- tests/functional/n/no_method_argument_py38.py | 6 ++++++ tests/functional/n/no_method_argument_py38.rc | 2 ++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tests/functional/n/no_method_argument_py38.py create mode 100644 tests/functional/n/no_method_argument_py38.rc diff --git a/ChangeLog b/ChangeLog index a22e2ce6f9..0a2bd3f673 100644 --- a/ChangeLog +++ b/ChangeLog @@ -26,6 +26,10 @@ Release date: TBA Close #3175 +* Do not emit ``no-method-argument`` for functions using positional only args. + + Close #3161 + What's New in Pylint 2.4.2? =========================== diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py index 986809fd34..9f5d099438 100644 --- a/pylint/checkers/classes.py +++ b/pylint/checkers/classes.py @@ -1460,7 +1460,12 @@ def _check_first_arg_for_type(self, node, metaclass=0): # don't care about functions with unknown argument (builtins) if node.args.args is None: return - first_arg = node.args.args and node.argnames()[0] + if node.args.args: + first_arg = node.argnames()[0] + elif node.args.posonlyargs: + first_arg = node.args.posonlyargs[0].name + else: + first_arg = None self._first_attrs.append(first_arg) first = self._first_attrs[-1] # static method @@ -1474,7 +1479,7 @@ def _check_first_arg_for_type(self, node, metaclass=0): return self._first_attrs[-1] = None # class / regular method with no args - elif not node.args.args: + elif not node.args.args and not node.args.posonlyargs: self.add_message("no-method-argument", node=node) # metaclass elif metaclass: diff --git a/tests/functional/n/no_method_argument_py38.py b/tests/functional/n/no_method_argument_py38.py new file mode 100644 index 0000000000..e7a4ded2bd --- /dev/null +++ b/tests/functional/n/no_method_argument_py38.py @@ -0,0 +1,6 @@ +# pylint: disable=missing-docstring + + +class Cls: + def __init__(self, obj, /): + self.obj = obj diff --git a/tests/functional/n/no_method_argument_py38.rc b/tests/functional/n/no_method_argument_py38.rc new file mode 100644 index 0000000000..85fc502b37 --- /dev/null +++ b/tests/functional/n/no_method_argument_py38.rc @@ -0,0 +1,2 @@ +[testoptions] +min_pyver=3.8