pythonargumentspylint

I have a pylint error: "W1113: keyword-arg-before-vararg" and don't know how to fix it


I have this code

class BaseCompareFeatureWithDefaults(recordlinkage.base.BaseCompareFeature):
    def __init__(self, labels_left="", labels_right="", *args, **kwargs) -> None:
        super().__init__(labels_left, labels_right, *args, **kwargs)

And I have this pylint error W1113: Keyword argument before variable positional arguments list in the definition of __init__ function (keyword-arg-before-vararg). It means that pylint wants *args, **kwargs after self. I don't know how to resolve this error and should I? Might be I could skip it/disable it?

I tried to change the order to self, *args, **kwargs, labels_left="", labels_right="" but if I do it I have this message in VS code: Parameter cannot follow "**" parameter Pylance and code does not work.


Solution

  • Named keyword arguments should come after positional varargs but before keyword varargs, i.e.:

    def __init__(self, *args, labels_left="", labels_right="", **kwargs) -> None: