Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions discord/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
import re
import warnings
from importlib.metadata import PackageNotFoundError, version

from typing_extensions import TypedDict
from typing import TypedDict

__all__ = ("__version__", "VersionInfo", "version_info")

Expand Down
25 changes: 22 additions & 3 deletions discord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,28 @@ def __init__(
):
# self.ws is set in the connect method
self.ws: DiscordWebSocket = None # type: ignore
self.loop: asyncio.AbstractEventLoop = (
asyncio.get_event_loop() if loop is None else loop
)
# Prefer an explicitly provided loop. If none is provided, try to use
# a running loop (when constructed inside async code) and otherwise
# fall back to the event loop policy's get_event_loop implementation
# to avoid the deprecation warning for asyncio.get_event_loop().
if loop is not None:
self.loop: asyncio.AbstractEventLoop = loop
else:
try:
self.loop = asyncio.get_running_loop()
except RuntimeError:
# No running loop in this thread; explicitly create a new
# event loop and set it as the current event loop for this
# thread. This mirrors the previous behavior of
# asyncio.get_event_loop() (which would create and set a loop)
# but avoids emitting the deprecation warning on Python >=3.11.
self.loop = asyncio.new_event_loop()
try:
asyncio.set_event_loop(self.loop)
except Exception as exc:
# If for some reason setting the loop fails, log the exception and continue
# using the locally created loop without setting it.
logging.exception("Failed to set event loop: %s", exc)
self._listeners: dict[str, list[tuple[asyncio.Future, Callable[..., bool]]]] = (
{}
)
Expand Down
4 changes: 1 addition & 3 deletions discord/commands/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
from discord.webhook.async_ import Webhook

if TYPE_CHECKING:
from typing import Awaitable, Callable

from typing_extensions import ParamSpec
from typing import Awaitable, Callable, ParamSpec

import discord

Expand Down
12 changes: 5 additions & 7 deletions discord/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,22 @@
import functools
import inspect
import re
import sys
import types
from collections import OrderedDict
from enum import Enum
from typing import (
TYPE_CHECKING,
Annotated,
Any,
Callable,
Coroutine,
Generator,
Generic,
Literal,
TypeVar,
Union,
get_args,
get_origin,
)

from ..channel import PartialMessageable, _threaded_guild_channel_factory
Expand Down Expand Up @@ -72,11 +75,6 @@
from .context import ApplicationContext, AutocompleteContext
from .options import Option, OptionChoice

if sys.version_info >= (3, 11):
from typing import Annotated, Literal, get_args, get_origin
else:
from typing_extensions import Annotated, Literal, get_args, get_origin

__all__ = (
"_BaseCommand",
"ApplicationCommand",
Expand All @@ -93,7 +91,7 @@
)

if TYPE_CHECKING:
from typing_extensions import Concatenate, ParamSpec
from typing import Concatenate, ParamSpec

from .. import Permissions
from ..cog import Cog
Expand Down
2 changes: 1 addition & 1 deletion discord/ext/commands/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from discord.message import Message

if TYPE_CHECKING:
from typing_extensions import ParamSpec
from typing import ParamSpec

from discord.abc import MessageableChannel
from discord.guild import Guild
Expand Down
2 changes: 1 addition & 1 deletion discord/ext/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
from .errors import *

if TYPE_CHECKING:
from typing_extensions import Concatenate, ParamSpec, TypeGuard
from typing import Concatenate, ParamSpec, TypeGuard

from discord.message import Message

Expand Down
4 changes: 2 additions & 2 deletions discord/types/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

from __future__ import annotations

from typing import Literal
from typing import Literal, TypedDict

from typing_extensions import NotRequired, TypedDict
from typing_extensions import NotRequired

from .snowflake import Snowflake
from .user import PartialUser
Expand Down
4 changes: 3 additions & 1 deletion discord/types/appinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

from __future__ import annotations

from typing_extensions import NotRequired, TypedDict
from typing import TypedDict

from typing_extensions import NotRequired

from .snowflake import Snowflake
from .team import Team
Expand Down
4 changes: 2 additions & 2 deletions discord/types/application_role_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

from __future__ import annotations

from typing import Literal
from typing import Literal, TypedDict

from typing_extensions import NotRequired, TypedDict
from typing_extensions import NotRequired

ApplicationRoleConnectionMetadataType = Literal[1, 2, 3, 4, 5, 6, 7, 8]

Expand Down
4 changes: 2 additions & 2 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

from typing import Literal, Union
from typing import Literal, TypedDict, Union

from typing_extensions import NotRequired, TypedDict
from typing_extensions import NotRequired

from .automod import AutoModRule
from .channel import ChannelType, PermissionOverwrite, VideoQualityMode
Expand Down
4 changes: 2 additions & 2 deletions discord/types/automod.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

from __future__ import annotations

from typing import Literal
from typing import Literal, TypedDict

from typing_extensions import NotRequired, TypedDict
from typing_extensions import NotRequired

from .snowflake import Snowflake

Expand Down
4 changes: 2 additions & 2 deletions discord/types/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

from __future__ import annotations

from typing import Literal, Union
from typing import Literal, TypedDict, Union

from typing_extensions import NotRequired, TypedDict
from typing_extensions import NotRequired

from ..enums import SortOrder
from ..flags import ChannelFlags
Expand Down
4 changes: 2 additions & 2 deletions discord/types/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

from __future__ import annotations

from typing import Literal, Union
from typing import Literal, TypedDict, Union

from typing_extensions import NotRequired, TypedDict
from typing_extensions import NotRequired

from .channel import ChannelType
from .emoji import PartialEmoji
Expand Down
4 changes: 2 additions & 2 deletions discord/types/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

from __future__ import annotations

from typing import Literal
from typing import Literal, TypedDict

from typing_extensions import NotRequired, TypedDict
from typing_extensions import NotRequired


class EmbedFooter(TypedDict):
Expand Down
4 changes: 2 additions & 2 deletions discord/types/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

from __future__ import annotations

from typing import Literal
from typing import Literal, TypedDict

from typing_extensions import NotRequired, Required, TypedDict
from typing_extensions import NotRequired, Required

from .activity import PartialPresenceUpdate
from .channel import GuildChannel
Expand Down
4 changes: 2 additions & 2 deletions discord/types/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

from __future__ import annotations

from typing import Literal, Union
from typing import Literal, TypedDict, Union

from typing_extensions import NotRequired, TypedDict
from typing_extensions import NotRequired

from .snowflake import Snowflake
from .user import User
Expand Down
4 changes: 3 additions & 1 deletion discord/types/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
from .message import AllowedMentions, Message
from ..interactions import InteractionChannel

from typing_extensions import NotRequired, TypedDict
from typing import TypedDict

from typing_extensions import NotRequired

ApplicationCommandType = Literal[1, 2, 3]

Expand Down
4 changes: 2 additions & 2 deletions discord/types/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

from __future__ import annotations

from typing import Literal, Union
from typing import Literal, TypedDict, Union

from typing_extensions import NotRequired, TypedDict
from typing_extensions import NotRequired

from .appinfo import PartialAppInfo
from .channel import PartialChannel
Expand Down
4 changes: 3 additions & 1 deletion discord/types/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
if TYPE_CHECKING:
from .interactions import InteractionMetadata, MessageInteraction

from typing_extensions import NotRequired, TypedDict
from typing import TypedDict

from typing_extensions import NotRequired


class ChannelMention(TypedDict):
Expand Down
4 changes: 2 additions & 2 deletions discord/types/monetization.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

from __future__ import annotations

from typing import Literal
from typing import Literal, TypedDict

from typing_extensions import NotRequired, TypedDict
from typing_extensions import NotRequired

from .snowflake import Snowflake

Expand Down
4 changes: 3 additions & 1 deletion discord/types/raw_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

from __future__ import annotations

from typing_extensions import NotRequired, TypedDict
from typing import TypedDict

from typing_extensions import NotRequired

from .automod import AutoModAction, AutoModTriggerType
from .emoji import PartialEmoji
Expand Down
4 changes: 3 additions & 1 deletion discord/types/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

from __future__ import annotations

from typing_extensions import NotRequired, TypedDict
from typing import TypedDict

from typing_extensions import NotRequired

from .snowflake import Snowflake

Expand Down
4 changes: 3 additions & 1 deletion discord/types/soundboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

from __future__ import annotations

from typing_extensions import NotRequired, TypedDict
from typing import TypedDict

from typing_extensions import NotRequired

from discord.types.user import User

Expand Down
4 changes: 2 additions & 2 deletions discord/types/sticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

from __future__ import annotations

from typing import Literal, Union
from typing import Literal, TypedDict, Union

from typing_extensions import NotRequired, TypedDict
from typing_extensions import NotRequired

from .snowflake import Snowflake
from .user import User
Expand Down
4 changes: 2 additions & 2 deletions discord/types/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

from __future__ import annotations

from typing import Literal
from typing import Literal, TypedDict

from typing_extensions import NotRequired, TypedDict
from typing_extensions import NotRequired

from ..flags import ChannelFlags
from .snowflake import Snowflake
Expand Down
4 changes: 2 additions & 2 deletions discord/types/voice.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

from __future__ import annotations

from typing import Literal
from typing import Literal, TypedDict

from typing_extensions import NotRequired, TypedDict
from typing_extensions import NotRequired

from .member import MemberWithUser
from .snowflake import Snowflake
Expand Down
4 changes: 2 additions & 2 deletions discord/types/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

from __future__ import annotations

from typing import Literal
from typing import Literal, TypedDict

from typing_extensions import NotRequired, TypedDict
from typing_extensions import NotRequired

from .channel import PartialChannel
from .snowflake import Snowflake
Expand Down
4 changes: 3 additions & 1 deletion discord/types/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

from __future__ import annotations

from typing_extensions import NotRequired, TypedDict
from typing import TypedDict

from typing_extensions import NotRequired

from .activity import Activity
from .snowflake import Snowflake
Expand Down
Loading
Loading