-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
E 1003: bad-super-call with two-argument super() call #4922
Comments
@DanielNoord Why was this error removed? This pattern of calling super with a different class seems just bad (even if it's a parent class), and I think this code should probably report some kind of error. Is there any realistic justification for this pattern? Also, inheriting from both classes with eponymous methods that don't call super also seems bad (one method is hidden). This could be another error. If both parent classes have a member that child classes need to call, then give them different names if possible. Otherwise, call them without super ( class HasWhoAmI:
def whoami(self):
pass
class ClassB(HasWhoAmI):
"Dummy B."
def whoami(self):
"""Print Name"""
super().whoami()
print("I am B")
class ClassC(HasWhoAmI):
"Dummy C."
def whoami(self):
"""Print Name"""
super().whoami()
print("hello? this is C.")
class ClassD(ClassB, ClassC):
"Dummy D."
def greet(self):
"""Print Name"""
self.whoami() # if you want all parents.
d = ClassD()
d.greet()
d.whoami() If you agree, then my suggestion would be to keep the test added by #6956, but instead of checking that no error is returned, check that an error is always returned 😄 |
Fixing this is a byproduct of fixing #2903. We discussed the issue there and in the More specifically:
I think that rationale applies to this issue as well? |
This code in the first comment doesn't seem like a reasonable pattern to me. I can't imagine a good reason for this, and it will suffer huge problems if you ever try to inherit from class Y(Child): ...
class X(GrandChild, Y): ... Now,
I disagree with this argument in the second comment as well. There are plenty of errors that pylint gives for valid Python code (e.g., f-string should be used), and I think these are a huge benefit to the Python community by steering people to write good Python code rather than just valid Python code.
This part of the second comment is also puzzling to me. In which situation is it useful? When does it have its place in multiple inheritance? I don't' think it does, so I humbly suggest switching the test added by #6956 around to ensuring that an error is always returned for this. |
Pylint emits various level of message. Fatal, error, warning, convention, refactor... If something would exit with an error code at runtime we raise an error level message, otherwise it should be warning or below. It's not to say that convention message are useless but it's important that pylint is clear about the seriousness of its messages. |
@NeilGirdhar Based on the 👍 I think we can go ahead and merge #6956 then? |
@DanielNoord I was just agreeing that pylint emits various levels of message. I still think that pylint should actively steer users away from |
Yeah, I think it makes sense to have that as an Perhaps we should open a new issue for this to discuss the level and name for the new message? |
Great idea. |
Bug description
Configuration
Command used
Pylint output
Expected behavior
Hi!
This is similar to #2903, but the major difference is multiple inheritance. I hope the example makes sense from a code design perspective (if not just imagine that classB and classC inherit from an ABC that has the
whoami
method as an abstractmethod).As far as I can tell, the flagged call to super is valid and the only way to actually call the
whoami
function ofClassC
onClassD
instances.Of course, in this example, switching the order of inheritance would be a simple solution, but just assume that based on other (not included) methods, the inheritance order has to be this way.
Thanks
Pylint version
OS / Environment
Linux 5.13.12-arch1-1 #1 SMP PREEMPT Wed, 18 Aug 2021 20:49:03 +0000 x86_64 GNU/Linux
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: