Recently I’ve been working on a code base that regularly does the pattern of deleting an attribute of an object, but only if that attribute exists. This can either be done with:
try: delattr(object, attr) except AttributeError: pass
if hasattr(object, attr): delattr(object, attr)
I imagine this is a fairly common pattern. My suggestion would be an option in
delattr to ignore if the attr doesn’t exist, something like
delattr(object, attr, missing='ignore')
Would anyone else find this useful?