From a612cf8472595172d99b23e8d9f9545194dcf99b Mon Sep 17 00:00:00 2001 From: yupix Date: Tue, 20 Feb 2024 16:53:01 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20poll=E3=81=AE=E5=9E=8B=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mipac/models/poll.py | 18 ++++++++---------- mipac/types/poll.py | 27 ++++++++++++--------------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/mipac/models/poll.py b/mipac/models/poll.py index 9a2db23..8c598be 100644 --- a/mipac/models/poll.py +++ b/mipac/models/poll.py @@ -1,8 +1,10 @@ from __future__ import annotations +from datetime import datetime from typing import TYPE_CHECKING from mipac.types.poll import ICreatePoll, IPoll, IPollChoice +from mipac.utils.format import str_to_datetime if TYPE_CHECKING: from mipac.manager import ClientManager @@ -10,8 +12,8 @@ if TYPE_CHECKING: class MiPoll: def __init__(self, poll: ICreatePoll) -> None: - self.multiple = poll.get("multiple", False) - self.choices = poll.get("choices") + self.choices = poll["choices"] + self.multiple = poll.get("multiple") self.expired_after = poll.get("expired_after") self.expires_at = poll.get("expires_at") @@ -40,16 +42,12 @@ class Poll: self.__client: ClientManager = client @property - def multiple(self) -> bool | None: - return self.__poll.get("multiple") + def expires_at(self) -> datetime: + return str_to_datetime(self.__poll["expires_at"]) @property - def expires_at(self) -> int | None: - return self.__poll.get("expired_at") - - @property - def expired_after(self) -> int | None: - return self.__poll.get("expired_after") + def multiple(self) -> bool: + return self.__poll["multiple"] @property def choices(self) -> list[PollChoice]: diff --git a/mipac/types/poll.py b/mipac/types/poll.py index 9d4e2bf..9aed2df 100644 --- a/mipac/types/poll.py +++ b/mipac/types/poll.py @@ -1,6 +1,6 @@ -from typing import TypedDict +from typing import NotRequired, TypedDict -__all__ = ("IPoll", "IPollChoice", "ICreatePoll", "IBasePoll") +__all__ = ("IPoll", "IPollChoice", "ICreatePoll") class IPollChoice(TypedDict): @@ -8,20 +8,17 @@ class IPollChoice(TypedDict): text: str votes: int - -class IBasePoll(TypedDict, total=False): - multiple: bool - expires_at: int - expired_after: int - - -class ICreatePoll(IBasePoll, total=False): - choices: list[str] - - -class IPoll(IBasePoll): +class IPoll(TypedDict): """ Questionnaire object """ - + expires_at: str + multiple: bool choices: list[IPollChoice] + + +class ICreatePoll(TypedDict): + choices: list[str] + multiple: NotRequired[bool] + expires_at: NotRequired[int] + expired_after: NotRequired[int]