Skip to content

Commit

Permalink
Reverse the order of positional args check in _check_first_arg_for_type
Browse files Browse the repository at this point in the history
Because the positional only arguments can appear before the normal positional
or keyword arguments, we need to first check the positional only ones for
the purpose of bad-mcs-* and similar methods.

Close #3230
  • Loading branch information
PCManticore committed Nov 8, 2019
1 parent c65cce4 commit d00e191
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pylint/checkers/classes.py
Expand Up @@ -1477,10 +1477,10 @@ 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
if node.args.args:
first_arg = node.argnames()[0]
elif node.args.posonlyargs:
if node.args.posonlyargs:
first_arg = node.args.posonlyargs[0].name
elif node.args.args:
first_arg = node.argnames()[0]
else:
first_arg = None
self._first_attrs.append(first_arg)
Expand Down
19 changes: 19 additions & 0 deletions tests/functional/r/regression_posonly_args.py
@@ -0,0 +1,19 @@
"""Test linting.
This is only intended to test pylint support for python 3.8's
positional-only arguments (PEP 570).
"""


class Foobar:
"""Class for frobulating the Foobar."""

@classmethod
def buildme(cls, /, value):
"""Construct object using alternate method."""
return cls(value).abc

def runme(self, qrs, /, xyz=None):
"""Do something funcy."""
if self.abc and qrs and xyz:
print("found something else")
2 changes: 2 additions & 0 deletions tests/functional/r/regression_posonly_args.rc
@@ -0,0 +1,2 @@
[testoptions]
min_pyver=3.8

0 comments on commit d00e191

Please sign in to comment.