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.
This commit is contained in:
Dmitry D. Chernov 2019-02-07 03:56:42 +10:00
parent 11896bb0e5
commit a248be5eca
2 changed files with 3 additions and 3 deletions

View File

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

View File

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