Skip to content

Commit

Permalink
Do not emit no-method-argument for functions using positional onl…
Browse files Browse the repository at this point in the history
…y args.

Close #3161
  • Loading branch information
PCManticore committed Oct 11, 2019
1 parent 3fc8c98 commit 15bae9f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Expand Up @@ -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?
===========================
Expand Down
9 changes: 7 additions & 2 deletions pylint/checkers/classes.py
Expand Up @@ -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
Expand All @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions 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
2 changes: 2 additions & 0 deletions tests/functional/n/no_method_argument_py38.rc
@@ -0,0 +1,2 @@
[testoptions]
min_pyver=3.8

0 comments on commit 15bae9f

Please sign in to comment.