mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
refactor(sessions):
remove BaseSession's initializer, add timeout ommitable field to base method model
This commit is contained in:
parent
15bcc0ba9f
commit
ea6a02bf97
5 changed files with 90 additions and 39 deletions
|
|
@ -13,6 +13,7 @@ if TYPE_CHECKING: # pragma: no cover
|
|||
from ..client.bot import Bot
|
||||
|
||||
T = TypeVar("T")
|
||||
DEFAULT_REQUEST_TIMEOUT_SECONDS = 60.0
|
||||
|
||||
|
||||
class Request(BaseModel):
|
||||
|
|
@ -55,6 +56,16 @@ class TelegramMethod(abc.ABC, BaseModel, Generic[T]):
|
|||
def build_request(self) -> Request: # pragma: no cover
|
||||
pass
|
||||
|
||||
request_timeout: float = DEFAULT_REQUEST_TIMEOUT_SECONDS
|
||||
|
||||
def dict(self, **kwargs: Any) -> Any:
|
||||
# override dict of pydantic.BaseModel to overcome exporting request_timeout field
|
||||
exclude = kwargs.pop("exclude", set())
|
||||
if isinstance(exclude, set):
|
||||
exclude.add("request_timeout")
|
||||
|
||||
return super().dict(exclude=exclude, **kwargs)
|
||||
|
||||
def build_response(self, data: Dict[str, Any]) -> Response[T]:
|
||||
# noinspection PyTypeChecker
|
||||
return Response[self.__returning__](**data) # type: ignore
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue