Use getattr() with default instead of clunky hasattr and ternary.
Add unit tests for 'type' AttributeError fixes.