mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 17:36:34 +03:00
Raise RuntimeError on with blocks that need async
This commit is contained in:
parent
9cbc088b76
commit
419fe6dca3
|
@ -483,6 +483,12 @@ class AuthMethods(MessageParseMethods, UserMethods):
|
|||
# region with blocks
|
||||
|
||||
def __enter__(self):
|
||||
if self._loop.is_running():
|
||||
raise RuntimeError(
|
||||
'You must use "async with" if the event loop '
|
||||
'is running (i.e. you are inside an "async def")'
|
||||
)
|
||||
|
||||
return self.start()
|
||||
|
||||
async def __aenter__(self):
|
||||
|
|
|
@ -379,6 +379,12 @@ class Conversation(ChatGetter):
|
|||
fut.cancel()
|
||||
|
||||
def __enter__(self):
|
||||
if self._client.loop.is_running():
|
||||
raise RuntimeError(
|
||||
'You must use "async with" if the event loop '
|
||||
'is running (i.e. you are inside an "async def")'
|
||||
)
|
||||
|
||||
return self._client.loop.run_until_complete(self.__aenter__())
|
||||
|
||||
async def __aenter__(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user