Raise RuntimeError on with blocks that need async

This commit is contained in:
Lonami Exo 2018-10-17 11:30:07 +02:00
parent 9cbc088b76
commit 419fe6dca3
2 changed files with 12 additions and 0 deletions

View File

@ -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):

View File

@ -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):