pylint icon indicating copy to clipboard operation
pylint copied to clipboard

Method with variadic args/kwargs but no `self` reports `no-method-argument` instead of `no-self-argument`

Open Jackenmen opened this issue 1 year ago • 2 comments

Bug description

# pylint: disable=missing-docstring

class MyClass:
    # correct warning: no-method-argument
    def no_args():
        """A method without a self argument or any other arguments."""

    # correct warning: no-self-argument
    def no_self_arg(arg):
        """A method without a self argument but with a standard argument."""

    # incorrect warning: no-method-argument
    def no_self_arg_but_varargs(*args):
        """A method without a self argument but with *args."""

    # incorrect warning: no-method-argument
    def no_self_arg_but_kwargs(**kwargs):
        """A method without a self argument but with **kwargs."""

    # incorrect warning: no-method-argument
    def no_self_arg_but_varargs_and_kwargs(*args, **kwargs):
        """A method without a self argument but with *args and **kwargs."""

    def correct(self):
        """Correct."""
        self.var = "correct"

Configuration

No response

Command used

pylint repro.py

Pylint output

************* Module repro
repro.py:5:4: E0211: Method has no argument (no-method-argument)
repro.py:9:4: E0213: Method should have "self" as first argument (no-self-argument)
repro.py:13:4: E0211: Method has no argument (no-method-argument)
repro.py:17:4: E0211: Method has no argument (no-method-argument)
repro.py:21:4: E0211: Method has no argument (no-method-argument)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

Expected behavior

I expected to see no-self-argument when a method has *args or **kwargs rather than no-method-argument as the latter is quite confusing as the method does have arguments.

Pylint version

pylint 2.15.3
astroid 2.12.10
Python 3.8.14 (default, Sep  8 2022, 00:02:07) 
[GCC 11.2.0]

OS / Environment

Kubuntu 22.04.1 LTS

Additional dependencies

No response

Jackenmen avatar Sep 20 '22 20:09 Jackenmen

I think that makes sense. Thank you for reporting it.

mbyrnepr2 avatar Sep 21 '22 09:09 mbyrnepr2

It would also be a nice to have that the wording for both no-method-argument and no-self-argument include the method name, that is

Method has no argument (no-method-argument) Method should have "self" as first argument (no-self-argument)

to be

Method NAME has no argument (no-method-argument) Method NAME should have "self" as first argument (no-self-argument)

clavedeluna avatar Sep 21 '22 14:09 clavedeluna

Yeah, having the name of the method would definitely be better for CLI use. (it's probably not the case because in IDE you know the name: it's the function you're hovering)

Pierre-Sassoulas avatar Sep 22 '22 20:09 Pierre-Sassoulas