Assert properties exist on disconnect

This commit is contained in:
Lonami Exo 2018-06-26 12:03:31 +02:00
parent 1da0018a5d
commit 9971145721

View File

@ -291,11 +291,14 @@ class TelegramBaseClient(abc.ABC):
""" """
Disconnects from Telegram. Disconnects from Telegram.
""" """
await self._sender.disconnect() # All properties may be ``None`` if `__init__` fails, and this
# method will be called from `__del__` which would crash then.
if self._sender:
await self._sender.disconnect()
if self._updates_handle: if self._updates_handle:
await self._updates_handle await self._updates_handle
if self.session:
self.session.close() self.session.close()
def __del__(self): def __del__(self):
# Python 3.5.2's ``asyncio`` mod seems to have a bug where it's not # Python 3.5.2's ``asyncio`` mod seems to have a bug where it's not