From 0b5c3cf256686c4572b086bb6dcf7a6e4e8b28bc Mon Sep 17 00:00:00 2001 From: Rapptz Date: Fri, 25 Feb 2022 10:44:53 -0500 Subject: [PATCH] [types] Fix types for channels and interactions --- discord/types/channel.py | 5 +++-- discord/types/interactions.py | 28 +++++++++++++++++----------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/discord/types/channel.py b/discord/types/channel.py index a35351e47..0e4846e3c 100644 --- a/discord/types/channel.py +++ b/discord/types/channel.py @@ -25,7 +25,7 @@ DEALINGS IN THE SOFTWARE. from typing import List, Literal, Optional, TypedDict, Union from .user import PartialUser from .snowflake import Snowflake -from .threads import ThreadMetadata, ThreadMember, ThreadArchiveDuration +from .threads import ThreadMetadata, ThreadMember, ThreadArchiveDuration, ThreadType OverwriteType = Literal[0, 1] @@ -38,7 +38,8 @@ class PermissionOverwrite(TypedDict): deny: str -ChannelType = Literal[0, 1, 2, 3, 4, 5, 6, 10, 11, 12, 13] +ChannelTypeWithoutThread = Literal[0, 1, 2, 3, 4, 5, 6, 13] +ChannelType = Union[ChannelTypeWithoutThread, ThreadType] class _BaseChannel(TypedDict): diff --git a/discord/types/interactions.py b/discord/types/interactions.py index b4d033ea1..1619734ea 100644 --- a/discord/types/interactions.py +++ b/discord/types/interactions.py @@ -26,7 +26,9 @@ from __future__ import annotations from typing import TYPE_CHECKING, Dict, List, Literal, TypedDict, Union -from .channel import ChannelType, ThreadMetadata + +from .channel import ChannelType, ChannelTypeWithoutThread, ThreadMetadata +from .threads import ThreadType from .member import Member from .message import Attachment from .role import Role @@ -40,25 +42,29 @@ if TYPE_CHECKING: InteractionType = Literal[1, 2, 3, 4, 5] -class PartialChannel(TypedDict): +class _BasePartialChannel(TypedDict): id: Snowflake name: str - type: ChannelType permissions: str -class PartialThread(PartialChannel): +class PartialChannel(_BasePartialChannel): + type: ChannelTypeWithoutThread + + +class PartialThread(_BasePartialChannel): + type: ThreadType thread_metadata: ThreadMetadata parent_id: Snowflake class ResolvedData(TypedDict, total=False): - users: Dict[Snowflake, User] - members: Dict[Snowflake, Member] - roles: Dict[Snowflake, Role] - channels: Dict[Snowflake, Union[PartialChannel, PartialThread]] - messages: Dict[Snowflake, Message] - attachments: Dict[Snowflake, Attachment] + users: Dict[str, User] + members: Dict[str, Member] + roles: Dict[str, Role] + channels: Dict[str, Union[PartialChannel, PartialThread]] + messages: Dict[str, Message] + attachments: Dict[str, Attachment] class _BaseApplicationCommandInteractionDataOption(TypedDict): @@ -114,7 +120,7 @@ ApplicationCommandInteractionDataOption = Union[ ] -class _BaseApplicationCommandInteractionDataOptional(TypedDict): +class _BaseApplicationCommandInteractionDataOptional(TypedDict, total=False): resolved: ResolvedData