mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Fix typing
This commit is contained in:
parent
b54805662f
commit
8a4b2a16dd
3 changed files with 12 additions and 8 deletions
|
|
@ -34,7 +34,7 @@ class SendMediaGroup(TelegramMethod[List[Message]]):
|
|||
|
||||
return Request(method="sendMediaGroup", data=data, files=files)
|
||||
|
||||
def prepare_input_media(self, data: Dict[str, Any], files: Dict[str, InputFile]):
|
||||
def prepare_input_media(self, data: Dict[str, Any], files: Dict[str, InputFile]) -> None:
|
||||
if not self.media:
|
||||
return
|
||||
for input_media in data.get("media", []): # type: Dict[str, Union[str, InputFile]]
|
||||
|
|
@ -44,5 +44,5 @@ class SendMediaGroup(TelegramMethod[List[Message]]):
|
|||
and isinstance(input_media["media"], InputFile)
|
||||
):
|
||||
tag = secrets.token_urlsafe(10)
|
||||
files[tag] = input_media.pop("media")
|
||||
files[tag] = input_media.pop("media") # type: ignore
|
||||
input_media["media"] = f"attach://{tag}"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Optional, TypeVar, Callable
|
||||
from typing import Optional, TypeVar, Callable, cast
|
||||
|
||||
from aiohttp import ClientSession, FormData
|
||||
|
||||
|
|
@ -18,10 +18,12 @@ class AiohttpSession(BaseSession):
|
|||
super(AiohttpSession, self).__init__(api=api, json_loads=json_loads, json_dumps=json_dumps)
|
||||
self._session: Optional[ClientSession] = None
|
||||
|
||||
async def create_session(self):
|
||||
async def create_session(self) -> ClientSession:
|
||||
if self._session is None or self._session.closed:
|
||||
self._session = ClientSession()
|
||||
|
||||
return self._session
|
||||
|
||||
async def close(self):
|
||||
if self._session is not None and not self._session.closed:
|
||||
await self._session.close()
|
||||
|
|
@ -38,15 +40,15 @@ class AiohttpSession(BaseSession):
|
|||
return form
|
||||
|
||||
async def make_request(self, token: str, call: TelegramMethod[T]) -> T:
|
||||
await self.create_session()
|
||||
session = await self.create_session()
|
||||
|
||||
request = call.build_request()
|
||||
url = self.api.api_url(token=token, method=request.method)
|
||||
form = self.build_form_data(request)
|
||||
|
||||
async with self._session.post(url, data=form) as response:
|
||||
raw_result = await response.json(loads=self.json_loads)
|
||||
async with session.post(url, data=form) as resp:
|
||||
raw_result = await resp.json(loads=self.json_loads)
|
||||
|
||||
response = call.build_response(raw_result)
|
||||
self.raise_for_status(response)
|
||||
return response.result
|
||||
return cast(T, response.result)
|
||||
|
|
|
|||
2
mypy.ini
Normal file
2
mypy.ini
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
[mypy]
|
||||
ignore_missing_imports = True
|
||||
Loading…
Add table
Add a link
Reference in a new issue