You can use `if getattr(self, 'session', None):`. It is cleaner and a bit faster.