How to safely get an object's class name when __getattribute__ may raise?