From a248be5ecafb809398a710394f3bccb6fde648ce Mon Sep 17 00:00:00 2001 From: "Dmitry D. Chernov" Date: Thu, 7 Feb 2019 03:56:42 +1000 Subject: [PATCH] Get rid of the exception constant This is antipattern because 'raise' doesn't copy the specified exception object, but simply throws a reference onto, so if the user wants to change the exception object in the handler, the constant will be changed as well. --- telethon/client/account.py | 2 +- telethon/client/users.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/telethon/client/account.py b/telethon/client/account.py index 472b3f0a..dc61038e 100644 --- a/telethon/client/account.py +++ b/telethon/client/account.py @@ -53,7 +53,7 @@ class _TakeoutClient: wrapped = [] for r in requests: if not isinstance(r, TLRequest): - raise _NOT_A_REQUEST + raise _NOT_A_REQUEST() await r.resolve(self, utils) wrapped.append(functions.InvokeWithTakeoutRequest(takeout_id, r)) diff --git a/telethon/client/users.py b/telethon/client/users.py index 61fcdc62..609b37a9 100644 --- a/telethon/client/users.py +++ b/telethon/client/users.py @@ -8,7 +8,7 @@ from ..errors import MultiError, RPCError from ..tl import TLObject, TLRequest, types, functions from ..helpers import retry_range -_NOT_A_REQUEST = TypeError('You can only invoke requests, not types!') +_NOT_A_REQUEST = lambda: TypeError('You can only invoke requests, not types!') class UserMethods(TelegramBaseClient): @@ -16,7 +16,7 @@ class UserMethods(TelegramBaseClient): requests = (request if utils.is_list_like(request) else (request,)) for r in requests: if not isinstance(r, TLRequest): - raise _NOT_A_REQUEST + raise _NOT_A_REQUEST() await r.resolve(self, utils) # Avoid making the request if it's already in a flood wait