can't we simplify these 3 lines to 

```python
return getattr(obj, key, default)
```