The class you are __del__() does not have __del__() . Therefore, an attempt to cause this error.
Now, if you expect your class to be used in a multiple inheritance scenario, the next class in method resolution order (MRO) may not be your class parent. And this class, whatever it may be, may have a __del__() method. So, if this case bothers you, you can use try and catch an AttributeError , or use hasattr() , or use getattr() with a dummy lambda as the default value.
Here is an example of each of them:
# there is a minor bug here, can you guess what it is? try: super().__del__(self) except AttributeError: pass # better version of the above s = super() try: s.__del__ except AttributeError: pass else: s.__del__(self) s = super() if hasattr(s, "__del__"): s.__del__(self) getattr(super(), "__del__", lambda self: None)(self)
source share