Search code examples
pythonpython-3.xpylintfalse-positive

Pylint error in Python


I'm getting many pylint false positive and it seems so ordinary that I cannot imagine it hasn't been solved yet :-/

The following code generates a false positive in pylint since it does not recognise keyword arguments correctly:

class A:
    def __init__(self, *t, x=None):
        if x==1:  # E0601, using variable 'x' before assignment
            x=2
        print(x)

A(x=1)

This is usually due to pylint misinterpreting keyword arguments after a *. Do you know if pylint is still active, where to report it, or how to find if someone has patched this yet? I cannot find something helpful with google :( Maybe by chance, someone knows a patch as it seems to ordinary...


Solution

  • This isn't actually valid Python (at least in 2.x). Specific keyword arguments must go before *args and **kwargs. You'll see an error if you try to paste this into the Python shell. It should look like this:

    def __init__(self, x=None, *t):