diff --git a/telethon/client/auth.py b/telethon/client/auth.py index ca8d24f5..15e8d4ac 100644 --- a/telethon/client/auth.py +++ b/telethon/client/auth.py @@ -1,8 +1,7 @@ import getpass import hashlib -import sys - import os +import sys from .messageparse import MessageParseMethods from .users import UserMethods @@ -459,3 +458,19 @@ class AuthMethods(MessageParseMethods, UserMethods): )) # endregion + + # region with blocks + + def __enter__(self): + return self.start() + + async def __aenter__(self): + return await self.start() + + def __exit__(self, *args): + self.disconnect() + + async def __aexit__(self, *args): + await self.disconnect() + + # endregion