mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Improve typing and reformat code
This commit is contained in:
parent
c674b5547b
commit
562e339262
4 changed files with 20 additions and 17 deletions
|
|
@ -1,7 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
from typing import TypeVar, Dict, Any
|
||||
from typing import Any, TypeVar
|
||||
|
||||
from ...utils.mixins import ContextInstanceMixin
|
||||
from ...utils.token import extract_bot_id, validate_token
|
||||
|
|
@ -41,7 +40,7 @@ class BaseBot(ContextInstanceMixin):
|
|||
def __hash__(self):
|
||||
return hash(self.__token)
|
||||
|
||||
def __eq__(self, other: BaseBot):
|
||||
def __eq__(self, other: Any) -> bool:
|
||||
if not isinstance(other, BaseBot):
|
||||
return False
|
||||
return hash(self) == hash(other)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
from typing import Callable, Optional, TypeVar, cast, Dict, Any
|
||||
from typing import Any, Callable, Dict, Optional, TypeVar, cast
|
||||
|
||||
from aiohttp import ClientSession, FormData
|
||||
|
||||
|
|
@ -61,12 +61,15 @@ class AiohttpSession(BaseSession):
|
|||
await self.create_session()
|
||||
return self
|
||||
|
||||
def __deepcopy__(self, memodict: Dict[str, Any]):
|
||||
def __deepcopy__(self: T, memo: Optional[Dict[int, Any]] = None) -> T:
|
||||
if memo is None:
|
||||
memo = {}
|
||||
|
||||
cls = self.__class__
|
||||
result = cls.__new__(cls)
|
||||
memodict[id(self)] = result
|
||||
memo[id(self)] = result
|
||||
for key, value in self.__dict__.items():
|
||||
# aiohttp ClientSession cannot be copied.
|
||||
copied_value = copy.deepcopy(value, memo=memodict) if key != '_session' else None
|
||||
copied_value = copy.deepcopy(value, memo=memo) if key != "_session" else None
|
||||
setattr(result, key, copied_value)
|
||||
return result
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue