Skip to content

Commit

Permalink
Improve import logic & __future__ annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
BobDotCom committed Oct 21, 2022
1 parent a8d903c commit aa702f6
Show file tree
Hide file tree
Showing 21 changed files with 56 additions and 149 deletions.
8 changes: 1 addition & 7 deletions discord/types/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,12 @@

from __future__ import annotations

import sys
from typing import Literal

from .._typed_dict import NotRequired, TypedDict
from .snowflake import Snowflake
from .user import PartialUser

if sys.version_info >= (3, 11):
from typing import NotRequired, TypedDict
else:
from typing_extensions import NotRequired, TypedDict


StatusType = Literal["idle", "dnd", "online", "offline"]


Expand Down
8 changes: 1 addition & 7 deletions discord/types/appinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,11 @@

from __future__ import annotations

import sys

from .._typed_dict import NotRequired, TypedDict
from .snowflake import Snowflake
from .team import Team
from .user import User

if sys.version_info >= (3, 11):
from typing import NotRequired, TypedDict
else:
from typing_extensions import NotRequired, TypedDict


class BaseAppInfo(TypedDict):
id: Snowflake
Expand Down
8 changes: 1 addition & 7 deletions discord/types/audit_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

from __future__ import annotations

import sys
from typing import Literal, Union

from .._typed_dict import NotRequired, TypedDict
from .automod import AutoModRule
from .channel import ChannelType, PermissionOverwrite, VideoQualityMode
from .guild import (
Expand All @@ -44,12 +44,6 @@
from .user import User
from .webhook import Webhook

if sys.version_info >= (3, 11):
from typing import NotRequired, TypedDict
else:
from typing_extensions import NotRequired, TypedDict


AuditLogEvent = Literal[
1,
10,
Expand Down
8 changes: 1 addition & 7 deletions discord/types/automod.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,11 @@

from __future__ import annotations

import sys
from typing import Literal

from .._typed_dict import NotRequired, TypedDict
from .snowflake import Snowflake

if sys.version_info >= (3, 11):
from typing import NotRequired, TypedDict
else:
from typing_extensions import NotRequired, TypedDict


AutoModTriggerType = Literal[1, 2, 3, 4]

AutoModEventType = Literal[1]
Expand Down
30 changes: 13 additions & 17 deletions discord/types/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,15 @@
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
import sys
from typing import List, Literal, Optional, Union
from __future__ import annotations

from typing import Literal, Union

from .._typed_dict import NotRequired, TypedDict
from .snowflake import Snowflake
from .threads import ThreadArchiveDuration, ThreadMember, ThreadMetadata
from .user import PartialUser

if sys.version_info >= (3, 11):
from typing import NotRequired, TypedDict
else:
from typing_extensions import NotRequired, TypedDict


OverwriteType = Literal[0, 1]


Expand All @@ -56,9 +52,9 @@ class _BaseChannel(TypedDict):
class _BaseGuildChannel(_BaseChannel):
guild_id: Snowflake
position: int
permission_overwrites: List[PermissionOverwrite]
permission_overwrites: list[PermissionOverwrite]
nsfw: bool
parent_id: Optional[Snowflake]
parent_id: Snowflake | None


class PartialChannel(_BaseChannel):
Expand All @@ -67,7 +63,7 @@ class PartialChannel(_BaseChannel):

class _TextChannelOptional(TypedDict, total=False):
topic: str
last_message_id: Optional[Snowflake]
last_message_id: Snowflake | None
last_pin_timestamp: str
rate_limit_per_user: int
default_auto_archive_duration: ThreadArchiveDuration
Expand All @@ -89,7 +85,7 @@ class NewsChannel(_BaseGuildChannel, _TextChannelOptional):


class VoiceChannel(_BaseGuildChannel):
rtc_region: NotRequired[Optional[str]]
rtc_region: NotRequired[str | None]
video_quality_mode: NotRequired[VideoQualityMode]
type: Literal[2]
bitrate: int
Expand All @@ -101,7 +97,7 @@ class CategoryChannel(_BaseGuildChannel):


class StageChannel(_BaseGuildChannel):
rtc_region: NotRequired[Optional[str]]
rtc_region: NotRequired[str | None]
topic: NotRequired[str]
type: Literal[13]
bitrate: int
Expand All @@ -112,7 +108,7 @@ class ThreadChannel(_BaseChannel):
member: NotRequired[ThreadMember]
owner_id: NotRequired[Snowflake]
rate_limit_per_user: NotRequired[int]
last_message_id: NotRequired[Optional[Snowflake]]
last_message_id: NotRequired[Snowflake | None]
last_pin_timestamp: NotRequired[str]
type: Literal[10, 11, 12]
guild_id: Snowflake
Expand All @@ -137,13 +133,13 @@ class ThreadChannel(_BaseChannel):
class DMChannel(TypedDict):
id: Snowflake
type: Literal[1]
last_message_id: Optional[Snowflake]
recipients: List[PartialUser]
last_message_id: Snowflake | None
recipients: list[PartialUser]


class GroupDMChannel(_BaseChannel):
type: Literal[3]
icon: Optional[str]
icon: str | None
owner_id: Snowflake


Expand Down
7 changes: 1 addition & 6 deletions discord/types/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,11 @@

from __future__ import annotations

import sys
from typing import Literal, Union

from .._typed_dict import NotRequired, TypedDict
from .emoji import PartialEmoji

if sys.version_info >= (3, 11):
from typing import NotRequired, TypedDict
else:
from typing_extensions import NotRequired, TypedDict

ComponentType = Literal[1, 2, 3, 4]
ButtonStyle = Literal[1, 2, 3, 4, 5]
InputTextStyle = Literal[1, 2]
Expand Down
12 changes: 5 additions & 7 deletions discord/types/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
import sys
from typing import List, Literal
from __future__ import annotations

if sys.version_info >= (3, 11):
from typing import NotRequired, TypedDict
else:
from typing_extensions import NotRequired, TypedDict
from typing import Literal

from .._typed_dict import NotRequired, TypedDict


class EmbedFooter(TypedDict):
Expand Down Expand Up @@ -94,4 +92,4 @@ class Embed(TypedDict, total=False):
video: EmbedVideo
provider: EmbedProvider
author: EmbedAuthor
fields: List[EmbedField]
fields: list[EmbedField]
9 changes: 5 additions & 4 deletions discord/types/emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
from __future__ import annotations

from typing import Optional, TypedDict
from typing import TypedDict

from .snowflake import Snowflake, SnowflakeList
from .user import User


class PartialEmoji(TypedDict):
id: Optional[Snowflake]
name: Optional[str]
id: Snowflake | None
name: str | None


class Emoji(PartialEmoji, total=False):
Expand All @@ -45,4 +46,4 @@ class Emoji(PartialEmoji, total=False):

class EditEmoji(TypedDict):
name: str
roles: Optional[SnowflakeList]
roles: SnowflakeList | None
7 changes: 1 addition & 6 deletions discord/types/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"""
from __future__ import annotations

import sys
from typing import Literal

from .._typed_dict import NotRequired, Required, TypedDict
from .activity import PartialPresenceUpdate
from .channel import GuildChannel
from .emoji import Emoji
Expand All @@ -39,11 +39,6 @@
from .voice import GuildVoiceState
from .welcome_screen import WelcomeScreen

if sys.version_info >= (3, 11):
from typing import NotRequired, Required, TypedDict
else:
from typing_extensions import NotRequired, Required, TypedDict


class Ban(TypedDict):
reason: str | None
Expand Down
7 changes: 1 addition & 6 deletions discord/types/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,12 @@

from __future__ import annotations

import sys
from typing import Literal, Union

from .._typed_dict import NotRequired, TypedDict
from .snowflake import Snowflake
from .user import User

if sys.version_info >= (3, 11):
from typing import NotRequired, TypedDict
else:
from typing_extensions import NotRequired, TypedDict


class IntegrationApplication(TypedDict):
bot: NotRequired[User]
Expand Down
8 changes: 1 addition & 7 deletions discord/types/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

from __future__ import annotations

import sys
from typing import TYPE_CHECKING, Literal, Union

from ..permissions import Permissions
Expand All @@ -41,12 +40,7 @@
if TYPE_CHECKING:
from .message import AllowedMentions, Message


if sys.version_info >= (3, 11):
from typing import NotRequired, TypedDict
else:
from typing_extensions import NotRequired, TypedDict

from .._typed_dict import NotRequired, TypedDict

ApplicationCommandType = Literal[1, 2, 3]

Expand Down
7 changes: 1 addition & 6 deletions discord/types/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,16 @@

from __future__ import annotations

import sys
from typing import Literal, Union

from .._typed_dict import NotRequired, TypedDict
from .appinfo import PartialAppInfo
from .channel import PartialChannel
from .guild import InviteGuild, _GuildPreviewUnique
from .scheduled_events import ScheduledEvent
from .snowflake import Snowflake
from .user import PartialUser

if sys.version_info >= (3, 11):
from typing import NotRequired, TypedDict
else:
from typing_extensions import NotRequired, TypedDict

InviteTargetType = Literal[1, 2]


Expand Down
7 changes: 1 addition & 6 deletions discord/types/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

from __future__ import annotations

import sys
from typing import TYPE_CHECKING, Literal

from .channel import ChannelType
Expand All @@ -41,11 +40,7 @@
if TYPE_CHECKING:
from .interactions import MessageInteraction


if sys.version_info >= (3, 11):
from typing import NotRequired, TypedDict
else:
from typing_extensions import NotRequired, TypedDict
from .._typed_dict import NotRequired, TypedDict


class ChannelMention(TypedDict):
Expand Down
11 changes: 3 additions & 8 deletions discord/types/raw_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,14 @@
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
import sys
from typing import List
from __future__ import annotations

from .._typed_dict import NotRequired, TypedDict
from .automod import AutoModAction, AutoModTriggerType
from .emoji import PartialEmoji
from .member import Member
from .snowflake import Snowflake

if sys.version_info >= (3, 11):
from typing import NotRequired, TypedDict
else:
from typing_extensions import NotRequired, TypedDict


class _MessageEventOptional(TypedDict, total=False):
guild_id: Snowflake
Expand All @@ -46,7 +41,7 @@ class MessageDeleteEvent(_MessageEventOptional):


class BulkMessageDeleteEvent(_MessageEventOptional):
ids: List[Snowflake]
ids: list[Snowflake]
channel_id: Snowflake


Expand Down
8 changes: 1 addition & 7 deletions discord/types/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,9 @@

from __future__ import annotations

import sys

from .._typed_dict import NotRequired, TypedDict
from .snowflake import Snowflake

if sys.version_info >= (3, 11):
from typing import NotRequired, TypedDict
else:
from typing_extensions import NotRequired, TypedDict


class Role(TypedDict):
tags: NotRequired[RoleTags]
Expand Down
Loading

0 comments on commit aa702f6

Please sign in to comment.