I have a class.
class IncorrectOfferDetailsOfferException(Exception):
def __init__(self, offer):
self.offerName = offer[0]
self.offerType = offer[1]
self.message = "Offer \"" + self.offerName + "\" could not be completed. It appears to be of type \"" + self.offerType + "\", but this may be what is wrong and causing the exception."
super(IncorrectOfferDetailsOfferException, self).__init__(self.message)
I want to write a more general class to expand it.
class BadOfferException(Exception):
def __init__(self, offer):
self.offerName = offer[0]
self.offerType = offer[1]
self.message = "Offer \"" + self.offerName + "\" caused a problem."
How can I relate those two together to remove the redundant code and override the more general message text with the more specific one? You know, class inheritance. I'm having a lot of trouble understanding how to use super the right way to do this.
except BadOfferException:, should that catch anIncorrectOfferDetailsOfferException? If so, then makeIncorrectOfferDetailsOfferExceptiona subclass ofBadOfferException. If not, there are other ways to share code—a mixin class, a class decorator, a helper function… So, decide that first, and then we can help you with the next step.