From 690a40be7719fa010ec05fe2b0efd9822bbc1d78 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Mon, 3 Jun 2019 19:28:22 +0200 Subject: [PATCH] Better behaviour for conversation.cancel() (#1183) --- telethon/tl/custom/conversation.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/telethon/tl/custom/conversation.py b/telethon/tl/custom/conversation.py index f6b69cd9..f4fa234d 100644 --- a/telethon/tl/custom/conversation.py +++ b/telethon/tl/custom/conversation.py @@ -418,8 +418,13 @@ class Conversation(ChatGetter): return self def cancel(self): - """Cancels the current conversation and exits the context manager.""" - raise _ConversationCancelled() + """ + Cancels the current conversation. Pending responses and subsequent + calls to get a response will raise ``asyncio.CancelledError``. + + This method is synchronous and should not be awaited. + """ + self._cancel_all() async def __aexit__(self, exc_type, exc_val, exc_tb): chat_id = utils.get_peer_id(self._chat_peer) @@ -430,11 +435,6 @@ class Conversation(ChatGetter): del self._client._conversations[self._id] self._cancel_all() - return isinstance(exc_val, _ConversationCancelled) __enter__ = helpers._sync_enter __exit__ = helpers._sync_exit - - -class _ConversationCancelled(InterruptedError): - pass