undo fix, update signatures in tests

This commit is contained in:
darksidecat 2021-10-04 21:14:51 +03:00
parent bdd5bb0d16
commit bc32ff727d
5 changed files with 14 additions and 16 deletions

View file

@ -133,11 +133,11 @@ class AiohttpSession(BaseSession):
return form
async def make_request(
self, bot: Bot, call: TelegramMethod[TelegramType], timeout: Optional[int] = None
self, bot: Bot, method: TelegramMethod[TelegramType], timeout: Optional[int] = None
) -> TelegramType:
session = await self.create_session()
request = call.build_request(bot)
request = method.build_request(bot)
url = self.api.api_url(token=bot.token, method=request.method)
form = self.build_form_data(request)
@ -147,10 +147,10 @@ class AiohttpSession(BaseSession):
) as resp:
raw_result = await resp.text()
except asyncio.TimeoutError:
raise TelegramNetworkError(method=call, message="Request timeout error")
raise TelegramNetworkError(method=method, message="Request timeout error")
except ClientError as e:
raise TelegramNetworkError(method=call, message=f"{type(e).__name__}: {e}")
response = self.check_response(method=call, status_code=resp.status, content=raw_result)
raise TelegramNetworkError(method=method, message=f"{type(e).__name__}: {e}")
response = self.check_response(method=method, status_code=resp.status, content=raw_result)
return cast(TelegramType, response.result)
async def stream_content(

View file

@ -53,7 +53,7 @@ NextRequestMiddlewareType = Callable[
RequestMiddlewareType = Union[
BaseRequestMiddleware,
Callable[
["Bot", TelegramMethod[TelegramType], NextRequestMiddlewareType],
[NextRequestMiddlewareType, "Bot", TelegramMethod[TelegramType]],
Awaitable[Response[TelegramType]],
],
]
@ -188,7 +188,7 @@ class BaseSession(abc.ABC):
) -> TelegramType:
middleware = partial(self.make_request, timeout=timeout)
for m in reversed(self.middlewares):
middleware = partial(m, make_request=middleware) # type: ignore
middleware = partial(m, middleware) # type: ignore
return await middleware(bot, method)
async def __aenter__(self) -> BaseSession:

View file

@ -21,16 +21,16 @@ class BaseRequestMiddleware(ABC):
@abstractmethod
async def __call__(
self,
make_request: NextRequestMiddlewareType,
bot: "Bot",
method: TelegramMethod[TelegramObject],
make_request: NextRequestMiddlewareType,
) -> Response[TelegramObject]:
"""
Execute middleware
:param make_request: Wrapped make_request in middlewares chain
:param bot: bot for request making
:param method: Request method (Subclass of :class:`aiogram.methods.base.TelegramMethod`)
:param make_request: Wrapped make_request in middlewares chain
:return: :class:`aiogram.methods.Response`
"""

View file

@ -1,5 +1,5 @@
import logging
from typing import TYPE_CHECKING, Awaitable, Callable, List, Optional, Type
from typing import TYPE_CHECKING, Any, Awaitable, Callable, List, Optional, Type
from aiogram import loggers
from aiogram.methods import TelegramMethod
@ -19,9 +19,7 @@ logger = logging.getLogger(__name__)
class RequestLogging(BaseRequestMiddleware):
def __init__(
self, ignore_methods: Optional[List[Type[TelegramMethod[TelegramObject]]]] = None
):
def __init__(self, ignore_methods: Optional[List[Type[TelegramMethod[Any]]]] = None):
"""
Middleware for logging outgoing requests
@ -31,9 +29,9 @@ class RequestLogging(BaseRequestMiddleware):
async def __call__(
self,
make_request: NextRequestMiddlewareType,
bot: "Bot",
method: TelegramMethod[TelegramObject],
make_request: NextRequestMiddlewareType,
) -> Response[TelegramObject]:
if type(method) not in self.ignore_methods:
loggers.middlewares.info(

View file

@ -245,14 +245,14 @@ class TestBaseSession:
flag_after = False
@bot.session.middleware
async def my_middleware(b, method, make_request):
async def my_middleware(make_request, b, method):
nonlocal flag_before, flag_after
flag_before = True
try:
assert isinstance(b, Bot)
assert isinstance(method, TelegramMethod)
return await make_request(bot, method)
return await make_request(b, method)
finally:
flag_after = True