Pylint: no-value-for-parameter false positive

Created on 19 Mar 2019  Â·  3Comments  Â·  Source: PyCQA/pylint

From https://github.com/PyCQA/pylint/issues/2778:

I'm not sure if this gives any new insights, but I just wanted to report that I'm able to trigger error 1120 with an even simpler construct, while also having a code example which is more or less exactly the same, but doesn't trigger this error.

E1120 triggered

# pylint: disable=missing-docstring,too-few-public-methods,mixed-indentation,invalid-name

class Base():
    def __init__(self, foo, *args):
        self._foo = foo
        self._args = args

class Child(Base):
    pass


class SomethingElse():
    def __init__(self, *args):
        self._child = Child(*args)

Output

************* Module E1120-Trigger
E1120-Trigger.py:14:16: E1120: No value for argument 'foo' in constructor call (no-value-for-parameter)

-----------------------------------

Your code has been rated at 4.44/10

E1120 not triggered

# pylint: disable=missing-docstring,too-few-public-methods,mixed-indentation,invalid-name

class Base():
    def __init__(self, foo, *args):
        self._foo = foo
        self._args = args

class Child(Base):
    def __init__(self, *args):
        super().__init__(*args)
        self._bar = True


class SomethingElse():
    def __init__(self, *args):
        self._child = Child(*args)

Output


------------------------------------

Your code has been rated at 10.00/10

Conclusion

The difference is in the explicit call to the parent __init__() method in the second example. With this in place, E1120 is not triggered. In the first example, E1120 is triggered in the last line where a Child instance is created.

pylint --version output

pylint 2.3.1
astroid 2.2.5
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)]
bug checkers

Most helpful comment

I'll might give this a try, but can't promise because the legal clearance in my company for providing code to OSS projects is… exhausting, so to say. But that hint on where to start looking into this is actually pretty useful, thanks! I'm new to pylint development, so a starting point is a good thing.

All 3 comments

Thanks for following up on this. I'd be glad for a fix for this, because it's messing my linting results now due to a code change in my project.

Hey @0xLeon Sure thing, feel free to tackle a PR!
This check is emitted in pylint/checkers/typecheck.py, we'll need to adapt that detection code to account for the case when the first parameter is a positional one, followed by variadic parameters.

I'll might give this a try, but can't promise because the legal clearance in my company for providing code to OSS projects is… exhausting, so to say. But that hint on where to start looking into this is actually pretty useful, thanks! I'm new to pylint development, so a starting point is a good thing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

glmdgrielson picture glmdgrielson  Â·  3Comments

DGalt picture DGalt  Â·  3Comments

DevynCJohnson picture DevynCJohnson  Â·  3Comments

sambarluc picture sambarluc  Â·  3Comments

pylint-bot picture pylint-bot  Â·  3Comments