chore: pollの型を修正

pull/109/head
yupix 7 months ago
parent 0550155f27
commit a612cf8472
No known key found for this signature in database
GPG Key ID: 2FF705F5C56D9C06

@ -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]:

@ -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]

Loading…
Cancel
Save