mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-08 12:59:46 +00:00
Reduce __enter__/__exit__ boilerplate for sync ctx managers
This commit is contained in:
@@ -3,7 +3,7 @@ import itertools
|
||||
import string
|
||||
|
||||
from .users import UserMethods
|
||||
from .. import utils
|
||||
from .. import helpers, utils
|
||||
from ..requestiter import RequestIter
|
||||
from ..tl import types, functions, custom
|
||||
|
||||
@@ -69,17 +69,8 @@ class _ChatAction:
|
||||
|
||||
self._task = None
|
||||
|
||||
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__())
|
||||
|
||||
def __exit__(self, *args):
|
||||
return self._client.loop.run_until_complete(self.__aexit__(*args))
|
||||
__enter__ = helpers._sync_enter
|
||||
__exit__ = helpers._sync_exit
|
||||
|
||||
async def _update(self):
|
||||
try:
|
||||
|
Reference in New Issue
Block a user