diff --git a/mipac/actions/channel.py b/mipac/actions/channel.py index c97cd0f..6d07f99 100644 --- a/mipac/actions/channel.py +++ b/mipac/actions/channel.py @@ -299,10 +299,7 @@ class ClientChannelActions(AbstractAction): } ) raw_channel: IChannel = await self._session.request( - Route("POST", "/api/channels/update"), - json=data, - auth=True, - remove_none=False + Route("POST", "/api/channels/update"), json=data, auth=True, remove_none=False ) return Channel(raw_channel=raw_channel, client=self._client) diff --git a/mipac/actions/drive/files.py b/mipac/actions/drive/files.py index 35acf96..b4580cc 100644 --- a/mipac/actions/drive/files.py +++ b/mipac/actions/drive/files.py @@ -341,7 +341,7 @@ class FileActions(ClientFileActions): ) return [File(raw_file, client=self._client) for raw_file in raw_files] - async def find(self, name: str, folder_id:str|None=None) -> list[File]: + async def find(self, name: str, folder_id: str | None = None) -> list[File]: """Find a file by its name Endpoint: `/api/drive/files/find` diff --git a/mipac/actions/drive/folders.py b/mipac/actions/drive/folders.py index 391f186..46328c9 100644 --- a/mipac/actions/drive/folders.py +++ b/mipac/actions/drive/folders.py @@ -297,7 +297,7 @@ class FolderActions(ClientFolderActions): limit: int = 10, since_id: str | None = None, until_id: str | None = None, - folder_id: str|None=None, + folder_id: str | None = None, ) -> list[Folder]: """Get folders @@ -411,7 +411,7 @@ class FolderActions(ClientFolderActions): return Folder(raw_folder=raw_folder, client=self._client) async def update( - self, folder_id: str |None=None, name: str | None = None, parent_id: str | None = None + self, folder_id: str | None = None, name: str | None = None, parent_id: str | None = None ) -> Folder: """Update a folder diff --git a/mipac/actions/poll.py b/mipac/actions/poll.py index c8cc917..98f45d7 100644 --- a/mipac/actions/poll.py +++ b/mipac/actions/poll.py @@ -60,7 +60,7 @@ class PollActions(ClientPollActions): Route("POST", "/api/notes/polls/recommendation"), json=data, pagination_type="count", - auth=True + auth=True, ) while True: diff --git a/mipac/actions/reaction.py b/mipac/actions/reaction.py index 5f80abe..11977ab 100644 --- a/mipac/actions/reaction.py +++ b/mipac/actions/reaction.py @@ -25,7 +25,7 @@ class ReactionActions(AbstractAction): """Add reaction to note Endpoint: `/api/notes/reactions/create` - + Parameters ---------- reaction : str @@ -48,14 +48,14 @@ class ReactionActions(AbstractAction): async def remove(self, note_id: str | None = None) -> bool: """Remove reaction from note - + Endpoint: `/api/notes/reactions/delete` Parameters ---------- note_id : str, optional note id, by default None - + Returns ------- bool diff --git a/mipac/actions/username.py b/mipac/actions/username.py index 72d9d14..af7aafb 100644 --- a/mipac/actions/username.py +++ b/mipac/actions/username.py @@ -19,6 +19,6 @@ class UsernameActions(AbstractAction): async def available(self, username: str) -> UsernameAvailable: data = {"username": username} res: IUsernameAvailable = await self.__session.request( - Route('POST', "/api/username/available"), json=data, auth=True + Route("POST", "/api/username/available"), json=data, auth=True ) return UsernameAvailable(res) diff --git a/mipac/manager/drive/drive.py b/mipac/manager/drive/drive.py index 4a680db..25a6305 100644 --- a/mipac/manager/drive/drive.py +++ b/mipac/manager/drive/drive.py @@ -28,4 +28,6 @@ class DriveManager(AbstractManager): return ClientFileManager(file_id=file_id, session=self.__session, client=self.__client) def _create_client_folder_manager(self, *, folder_id: str) -> ClientFolderManager: - return ClientFolderManager(folder_id=folder_id, session=self.__session, client=self.__client) + return ClientFolderManager( + folder_id=folder_id, session=self.__session, client=self.__client + ) diff --git a/mipac/manager/drive/folders.py b/mipac/manager/drive/folders.py index decab5a..c272d68 100644 --- a/mipac/manager/drive/folders.py +++ b/mipac/manager/drive/folders.py @@ -15,7 +15,6 @@ if TYPE_CHECKING: class ClientFolderManager(AbstractManager): - def __init__(self, folder_id: str, *, session: HTTPClient, client: ClientManager): self.__folder_id: str = folder_id self.__session: HTTPClient = session diff --git a/mipac/manager/poll.py b/mipac/manager/poll.py index 63af1d0..7a3f0d5 100644 --- a/mipac/manager/poll.py +++ b/mipac/manager/poll.py @@ -9,19 +9,21 @@ if TYPE_CHECKING: from mipac.http import HTTPClient from mipac.manager.client import ClientManager + class ClientPollManager(AbstractManager): - def __init__(self, note_id: str|None=None, *, session: HTTPClient, client: ClientManager): + def __init__(self, note_id: str | None = None, *, session: HTTPClient, client: ClientManager): self.__note_id: str | None = note_id self.__session: HTTPClient = session self.__client: ClientManager = client - + @property def action(self) -> ClientPollActions: return ClientPollActions( note_id=self.__note_id, session=self.__session, client=self.__client, - ) + ) + class PollManager(AbstractManager): def __init__(self, note_id: str | None = None, *, session: HTTPClient, client: ClientManager): diff --git a/mipac/manager/username.py b/mipac/manager/username.py index fd3612f..15f0d6e 100644 --- a/mipac/manager/username.py +++ b/mipac/manager/username.py @@ -14,7 +14,7 @@ class UsernameManager(AbstractManager): def __init__(self, *, session: HTTPClient, client: ClientManager): self.__session: HTTPClient = session self.__client: ClientManager = client - + @property def action(self) -> UsernameActions: return UsernameActions(session=self.__session, client=self.__client) diff --git a/mipac/models/clip.py b/mipac/models/clip.py index 9669e01..13acfc9 100644 --- a/mipac/models/clip.py +++ b/mipac/models/clip.py @@ -61,7 +61,6 @@ class Clip(AbstractModel): """The number of times the clip has been favorited""" return self.__clip["favorited_count"] - @property def is_favorited(self) -> bool: """Whether the clip is favorited""" diff --git a/mipac/models/invite.py b/mipac/models/invite.py index c0f6f31..6ceb167 100644 --- a/mipac/models/invite.py +++ b/mipac/models/invite.py @@ -73,11 +73,12 @@ class InviteCode: def api(self) -> ClientInviteManager: return self.__client._create_client_invite_manager(invite_id=self.id) + class InviteLimit: - def __init__(self, raw_invite_limit: IInviteLimit, *, client:ClientManager) -> None: + def __init__(self, raw_invite_limit: IInviteLimit, *, client: ClientManager) -> None: self.__raw_invite_limit: IInviteLimit = raw_invite_limit self.__client = client - + @property def remaining(self) -> int | None: return self.__raw_invite_limit["remaining"] diff --git a/mipac/models/lite/ad.py b/mipac/models/lite/ad.py index 50aab53..4e1b907 100644 --- a/mipac/models/lite/ad.py +++ b/mipac/models/lite/ad.py @@ -1,8 +1,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Generic, TypeVar +from typing import TYPE_CHECKING, TypeVar -from mipac.abstract.model import AbstractModel from mipac.types.ads import IAdPlaces, IPartialAd if TYPE_CHECKING: @@ -12,7 +11,7 @@ if TYPE_CHECKING: T = TypeVar("T", bound=IPartialAd) -class PartialAd(AbstractModel, Generic[T]): +class PartialAd[T: IPartialAd]: def __init__(self, raw_ad: T, *, client: ClientManager) -> None: self._raw_ad: T = raw_ad diff --git a/mipac/models/lite/meta.py b/mipac/models/lite/meta.py index d36f8fd..0ab5cac 100644 --- a/mipac/models/lite/meta.py +++ b/mipac/models/lite/meta.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Generic, TypeVar +from typing import TYPE_CHECKING from mipac.abstract.model import AbstractModel from mipac.models.lite.ad import PartialAd @@ -9,8 +9,6 @@ from mipac.types.meta import IPartialMeta, IPolicies if TYPE_CHECKING: from mipac.manager.client import ClientManager -T = TypeVar("T", bound=IPartialMeta) - class Policies(AbstractModel): def __init__(self, raw_policies: IPolicies) -> None: @@ -118,7 +116,7 @@ class Policies(AbstractModel): return self.__raw_policies["rate_limit_factor"] -class PartialMeta(AbstractModel, Generic[T]): +class PartialMeta[T: IPartialMeta]: def __init__(self, raw_meta: T, *, client: ClientManager) -> None: self._raw_meta: T = raw_meta self.__client: ClientManager = client diff --git a/mipac/models/lite/role.py b/mipac/models/lite/role.py index 1b82bc1..4733ba6 100644 --- a/mipac/models/lite/role.py +++ b/mipac/models/lite/role.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Generic, TypeVar +from typing import TYPE_CHECKING from mipac.types.roles import IPartialRole @@ -8,10 +8,8 @@ if TYPE_CHECKING: from mipac.manager.admins.roles import AdminRolesModelManager from mipac.manager.client import ClientManager -T = TypeVar("T", bound=IPartialRole) - -class PartialRole(Generic[T]): +class PartialRole[T: IPartialRole]: def __init__(self, role_data: T, *, client: ClientManager) -> None: self._raw_role: T = role_data self.__client = client diff --git a/mipac/models/lite/user.py b/mipac/models/lite/user.py index 13c0272..db4b1fd 100644 --- a/mipac/models/lite/user.py +++ b/mipac/models/lite/user.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Generic, TypeVar +from typing import TYPE_CHECKING from mipac.models.lite.instance import LiteInstance from mipac.types.user import IAvatarDecoration, IBadgeRole, IPartialUser, IUserOnlineStatus @@ -10,11 +10,8 @@ if TYPE_CHECKING: from mipac.manager.client import ClientManager from mipac.manager.user import ClientUserManager -T = TypeVar("T", bound=IBadgeRole) -PU = TypeVar("PU", bound=IPartialUser) - -class BadgeRole(Generic[T]): +class BadgeRole[T: IBadgeRole]: def __init__(self, data: T, *, client: ClientManager) -> None: self._data: T = data self._client = client @@ -103,7 +100,7 @@ class AvatarDecoration: return self.__raw_avatar_decoration["url"] -class PartialUser(Generic[PU]): +class PartialUser[PU: IPartialUser]: def __init__(self, raw_user: PU, *, client: ClientManager) -> None: self._raw_user: PU = raw_user self._client: ClientManager = client @@ -266,7 +263,6 @@ class PartialUser(Generic[PU]): if badge_roles is None: return None return [BadgeRole(data, client=self._client) for data in badge_roles] - @property def api(self) -> ClientUserManager: diff --git a/mipac/models/user.py b/mipac/models/user.py index c00d328..ae569e2 100644 --- a/mipac/models/user.py +++ b/mipac/models/user.py @@ -1,7 +1,7 @@ from __future__ import annotations from datetime import datetime -from typing import TYPE_CHECKING, Generic, TypeVar +from typing import TYPE_CHECKING from mipac.abstract.model import AbstractModel from mipac.models.announcement import Announcement @@ -43,12 +43,8 @@ if TYPE_CHECKING: __all__ = ("PartialUser", "Achievement", "BlockingUser", "MeDetailed") -T = TypeVar("T", bound=IUserDetailedNotMeSchema) -FFC = TypeVar("FFC", bound=IFederationFollowCommon) - - -class FollowCommon(Generic[FFC]): +class FollowCommon[FFC: IFederationFollowCommon]: def __init__(self, raw_follow: FFC, *, client: ClientManager) -> None: self._raw_follow: FFC = raw_follow self._client: ClientManager = client @@ -507,7 +503,7 @@ class MeDetailedOnly: return self._raw_user.get("security_keys_list") -class UserDetailedNotMe(PartialUser[T], UserDetailedNotMeOnly, Generic[T]): +class UserDetailedNotMe[T: IUserDetailedNotMeSchema](PartialUser[T], UserDetailedNotMeOnly): def __init__(self, raw_user: T, *, client: ClientManager) -> None: super().__init__(raw_user, client=client) @@ -554,31 +550,35 @@ class UserList: def api(self) -> ClientUserListManager: return self.__client.user._create_client_user_list_manager(self.id) + class UserListMembership: - def __init__(self, raw_user_list_membership: IUserListMembership,*, client:ClientManager) -> None: + def __init__( + self, raw_user_list_membership: IUserListMembership, *, client: ClientManager + ) -> None: self.__raw_user_list_membership: IUserListMembership = raw_user_list_membership self.__client: ClientManager = client - + @property def id(self) -> str: return self.__raw_user_list_membership["id"] - + @property def created_at(self) -> datetime: return str_to_datetime(self.__raw_user_list_membership["created_at"]) - + @property def user_id(self) -> str: return self.__raw_user_list_membership["user_id"] - + @property def user(self) -> PartialUser: return PartialUser(self.__raw_user_list_membership["user"], client=self.__client) - + @property def with_replies(self) -> bool: return self.__raw_user_list_membership["with_replies"] + class FrequentlyRepliedUser: def __init__( self, diff --git a/mipac/models/username.py b/mipac/models/username.py index 1e565d4..1ee4c33 100644 --- a/mipac/models/username.py +++ b/mipac/models/username.py @@ -4,7 +4,7 @@ from mipac.types.username import IUsernameAvailable class UsernameAvailable: def __init__(self, raw_username_available: IUsernameAvailable) -> None: self.__raw_username_available: IUsernameAvailable = raw_username_available - + @property def available(self) -> bool: return self.__raw_username_available["available"] diff --git a/mipac/types/announcement.py b/mipac/types/announcement.py index e88493f..0d33cc2 100644 --- a/mipac/types/announcement.py +++ b/mipac/types/announcement.py @@ -3,17 +3,17 @@ from typing import NotRequired, TypedDict class IAnnouncement(TypedDict): id: str - createdAt: str - updatedAt: str | None + created_at: str + updated_at: str | None text: str title: str - imageUrl: str | None - icon: str | None + image_url: str | None + icon: str display: str - needConfirmationToRead: bool + need_confirmation_to_read: bool silence: bool - forYou: bool - isRead: NotRequired[bool] + for_you: bool + is_read: NotRequired[bool] class IAnnouncementDetailed(TypedDict): @@ -22,14 +22,15 @@ class IAnnouncementDetailed(TypedDict): id: str created_at: str updated_at: str | None - title: str text: str + title: str image_url: str | None - icon: str | None + icon: str display: str + need_confirmation_to_read: bool + silence: bool + is_active: bool for_existing_users: bool - silence: bool - need_confirmation_to_read: bool user_id: str | None reads: int diff --git a/mipac/types/invite.py b/mipac/types/invite.py index 826c3e6..ef8ca95 100644 --- a/mipac/types/invite.py +++ b/mipac/types/invite.py @@ -13,5 +13,6 @@ class IInviteCode(TypedDict): used_at: str | None used: bool + class IInviteLimit(TypedDict): remaining: int | None diff --git a/mipac/types/meta.py b/mipac/types/meta.py index c5427ae..17918ef 100644 --- a/mipac/types/meta.py +++ b/mipac/types/meta.py @@ -247,6 +247,4 @@ class IUpdateMetaBody(TypedDict, total=False): object_storage_use_proxy: bool object_storage_set_public_read: bool object_storage_s3_force_path_style: bool - server_rules: NotRequired[ - list[str] - ] # v13.11.3以降のバージョンから追加。その場合は使わないとエラー出るかも + server_rules: NotRequired[list[str]] # v13.11.3以降のバージョンから追加。その場合は使わないとエラー出るかも diff --git a/mipac/types/note.py b/mipac/types/note.py index 747af6e..0a815c3 100644 --- a/mipac/types/note.py +++ b/mipac/types/note.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Any, Generic, Literal, NotRequired, Optional, TypedDict, TypeVar +from typing import Any, Literal, NotRequired, Optional, TypedDict, TypeVar from mipac.types.drive import IFile from mipac.types.emoji import ICustomEmojiLite @@ -18,7 +18,7 @@ class INoteState(TypedDict): is_muted_thread: bool -class INoteUpdated(TypedDict, Generic[T]): +class INoteUpdated[T](TypedDict): type: Literal["noteUpdated"] body: T diff --git a/mipac/types/username.py b/mipac/types/username.py index 051c98b..e593b97 100644 --- a/mipac/types/username.py +++ b/mipac/types/username.py @@ -2,4 +2,4 @@ from typing import TypedDict class IUsernameAvailable(TypedDict): - available: bool \ No newline at end of file + available: bool diff --git a/mipac/utils/pagination.py b/mipac/utils/pagination.py index 2a4df5a..b6066d8 100644 --- a/mipac/utils/pagination.py +++ b/mipac/utils/pagination.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, AsyncGenerator, Generic, Literal, Type, TypeVar +from typing import TYPE_CHECKING, Any, AsyncGenerator, Literal, Type, TypeVar from mipac.abstract.model import AbstractModel from mipac.http import HTTPClient, Route @@ -8,11 +8,10 @@ from mipac.http import HTTPClient, Route if TYPE_CHECKING: from mipac.manager.client import ClientManager -T = TypeVar("T") M = TypeVar("M", bound=AbstractModel) -class Pagination(Generic[T]): +class Pagination[T]: def __init__( self, http_client: HTTPClient, diff --git a/mipac/utils/util.py b/mipac/utils/util.py index 4e24402..c69dc89 100644 --- a/mipac/utils/util.py +++ b/mipac/utils/util.py @@ -19,21 +19,24 @@ if HAS_ORJSON: else: _from_json = json.loads + class Missing: def __repr__(self) -> str: return "MISSING" - + def __bool__(self) -> bool: return False - + def __eq__(self, other: Any) -> bool: return isinstance(other, Missing) - + def __ne__(self, other: Any) -> bool: return not isinstance(other, Missing) + MISSING: Any = Missing() + def credentials_required(func): @functools.wraps(func) async def wrapper(self: AbstractAction, *args, **kwargs):