Pylint raises the warning: Useless super delegation in method '__init__' (useless-super-delegation)
for the SpecificError
class below.
class MyProjectExceptions(Exception):
"""The base class for all my project's exceptions."""
def __init__(self, message, func):
super(MyProjectExceptions, self).__init__(message) # Normal exception handling
self.func = func # Error origin for logging
class SpecificError(MyProjectExceptions):
"""Raise when a specific error occurs."""
def __init__(self, message, func):
super(SpecificError, self).__init__(message, func)
What is the correct way to pass the parameters to the superclass here?
If you call the SpecificError
class it will look for an __init__
. If it doesn't exist it will call the parent's __init__
. There is no need to add an __init__
here, since it's exactly the same like the parent class. It is basically code duplication.
You should do:
class SpecificError(MyProjectExceptions):
"""Raise when a specific error occurs."""
pass