1

Consider this

class Base:

    def __init__(self, bar: bool, **kwargs) -> None:
        self.bar = bar

    def foo(self, bar: bool, **kwargs):
        ...


class Child(Base):

    def __init__(self, bar: bool, bar2: int, **kwargs) -> None:
        super().__init__(bar, **kwargs)
        self.bar2 = bar2


    def foo(self, bar: bool, *, bar2: int, **kwargs):
        super().foo(bar, **kwargs)
        ...

How come, pylint raises this only on the method foo and not on __init__?

W0221: Number of parameters was 3 in 'Base.foo' and is now 4 in overriding 'Child.foo' method (arguments-differ)

1
  • 1
    You have to be able to use an instance of Child anywhere you could use an instance of Base, but that doesn't mean you have to create it in the same way. base_consumer(thing=Base(False)) and base_consumer(thing=Child(False, bar2=0)) are both OK if base_consumer can do thing.foo(True). Commented yesterday

1 Answer 1

0

Pylint treats __init__ like a constructor so it is acceptable for __init__ in subclass to add new parameters.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.