-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow adding parameters in an overridden method, without tripping arguments-differ
#1556
Comments
My view on this issue is that people could implement a different method that does the right thing with the default parameter, rather than overloading this method with a parameter that doesn't have a place in the base classes. |
Thank you for considering the use cases.
That IMO should be a separate check. I can see that people might want it, but LSP does not mandate what you describe there.
Perhaps Maybe two separate checks:
|
Apart of the names, which are a bit too long, this would make sense. |
Maybe slightly shorter: |
Is there a reason the extension of parameters is considered an anti-pattern by pylint? Specifically, I am thinking about things like auxiliary initializers: @classmethod
def from_foo(cls, arg1):
tmp = cls()
tmp.do_something(arg1)
return tmp Most often used for providing additional signatures for A derived class might want to add some extra parameter while re-using the name, to give the appearance of an overloaded method: @classmethod
def from_foo(cls, arg1, arg2=None):
tmp = super(myclass, cls).from_foo(arg1)
if arg:
tmp.do_something_else(arg2)
return tmp Now, it is indeed possible to right another function entirely that "does the right thing", but if it is conceived strictly as a superset of behavior of the other function, why should we pollute the namespace with a new function name? (Especially when pylint begins to bark when you have too many public functions.) |
The
arguments-differ
check will complain about a method which loses arguments that the superclass's method will allow. Such code violates the Liskov Substitution Principle, so IMO should triggerarguments-differ
.What is not desirable, IMO, is to have the same check complain about:
That code does not violate the LSP; an instance of
LoremIpsum
will function just fine as an instance ofIpsum
. Its methods can be called in the same way as methods ofIpsum
.How can I have PyLint not complain about code like this which AFAICT does not violate LSP, while still correctly flagging LSP violations?
The text was updated successfully, but these errors were encountered: