diff --git a/discord/abc.py b/discord/abc.py index 3b490f42b6..af7d5df8f5 100644 --- a/discord/abc.py +++ b/discord/abc.py @@ -118,7 +118,7 @@ async def _purge_messages_helper( channel: TextChannel | StageChannel | Thread | VoiceChannel, *, limit: int | None = 100, - check: Callable[[Message], bool] = MISSING, + check: Callable[[Message], bool] | utils.Undefined = MISSING, before: SnowflakeTime | None = None, after: SnowflakeTime | None = None, around: SnowflakeTime | None = None, @@ -1031,10 +1031,10 @@ async def move( self, *, beginning: bool, - offset: int = MISSING, - category: Snowflake | None = MISSING, - sync_permissions: bool = MISSING, - reason: str | None = MISSING, + offset: int | utils.Undefined = MISSING, + category: Snowflake | None | utils.Undefined = MISSING, + sync_permissions: bool | utils.Undefined = MISSING, + reason: str | None | utils.Undefined = MISSING, ) -> None: ... @overload @@ -1042,10 +1042,10 @@ async def move( self, *, end: bool, - offset: int = MISSING, - category: Snowflake | None = MISSING, - sync_permissions: bool = MISSING, - reason: str = MISSING, + offset: int | utils.Undefined = MISSING, + category: Snowflake | None | utils.Undefined = MISSING, + sync_permissions: bool | utils.Undefined = MISSING, + reason: str | utils.Undefined = MISSING, ) -> None: ... @overload @@ -1053,10 +1053,10 @@ async def move( self, *, before: Snowflake, - offset: int = MISSING, - category: Snowflake | None = MISSING, - sync_permissions: bool = MISSING, - reason: str = MISSING, + offset: int | utils.Undefined = MISSING, + category: Snowflake | None | utils.Undefined = MISSING, + sync_permissions: bool | utils.Undefined = MISSING, + reason: str | utils.Undefined = MISSING, ) -> None: ... @overload @@ -1064,10 +1064,10 @@ async def move( self, *, after: Snowflake, - offset: int = MISSING, - category: Snowflake | None = MISSING, - sync_permissions: bool = MISSING, - reason: str = MISSING, + offset: int | utils.Undefined = MISSING, + category: Snowflake | None | utils.Undefined = MISSING, + sync_permissions: bool | utils.Undefined = MISSING, + reason: str | utils.Undefined = MISSING, ) -> None: ... async def move(self, **kwargs) -> None: diff --git a/discord/application_role_connection.py b/discord/application_role_connection.py index dc4ef01d83..3e22d55cc1 100644 --- a/discord/application_role_connection.py +++ b/discord/application_role_connection.py @@ -27,7 +27,7 @@ from typing import TYPE_CHECKING from .enums import ApplicationRoleConnectionMetadataType, try_enum -from .utils import MISSING +from .utils import MISSING, Undefined if TYPE_CHECKING: from .types.application_role_connection import ( @@ -77,8 +77,8 @@ def __init__( key: str, name: str, description: str, - name_localizations: dict[str, str] = MISSING, - description_localizations: dict[str, str] = MISSING, + name_localizations: dict[str, str] | Undefined = MISSING, + description_localizations: dict[str, str] | Undefined = MISSING, ): self.type: ApplicationRoleConnectionMetadataType = type self.key: str = key diff --git a/discord/asset.py b/discord/asset.py index 07c7ca8e7b..eeb78e2e9c 100644 --- a/discord/asset.py +++ b/discord/asset.py @@ -333,9 +333,9 @@ def is_animated(self) -> bool: def replace( self, *, - size: int = MISSING, - format: ValidAssetFormatTypes = MISSING, - static_format: ValidStaticFormatTypes = MISSING, + size: int | utils.Undefined = MISSING, + format: ValidAssetFormatTypes | utils.Undefined = MISSING, + static_format: ValidStaticFormatTypes | utils.Undefined = MISSING, ) -> Asset: """Returns a new asset with the passed components replaced. diff --git a/discord/automod.py b/discord/automod.py index c4b1e23c0e..27c9e52f9f 100644 --- a/discord/automod.py +++ b/discord/automod.py @@ -92,9 +92,9 @@ class AutoModActionMetadata: def __init__( self, - channel_id: int = MISSING, - timeout_duration: timedelta = MISSING, - custom_message: str = MISSING, + channel_id: int | utils.Undefined = MISSING, + timeout_duration: timedelta | utils.Undefined = MISSING, + custom_message: str | utils.Undefined = MISSING, ): self.channel_id: int = channel_id self.timeout_duration: timedelta = timeout_duration @@ -247,11 +247,11 @@ class AutoModTriggerMetadata: def __init__( self, - keyword_filter: list[str] = MISSING, - regex_patterns: list[str] = MISSING, - presets: list[AutoModKeywordPresetType] = MISSING, - allow_list: list[str] = MISSING, - mention_total_limit: int = MISSING, + keyword_filter: list[str] | utils.Undefined = MISSING, + regex_patterns: list[str] | utils.Undefined = MISSING, + presets: list[AutoModKeywordPresetType] | utils.Undefined = MISSING, + allow_list: list[str] | utils.Undefined = MISSING, + mention_total_limit: int | utils.Undefined = MISSING, ): self.keyword_filter = keyword_filter self.regex_patterns = regex_patterns @@ -483,13 +483,13 @@ async def delete(self, reason: str | None = None) -> None: async def edit( self, *, - name: str = MISSING, - event_type: AutoModEventType = MISSING, - trigger_metadata: AutoModTriggerMetadata = MISSING, - actions: list[AutoModAction] = MISSING, - enabled: bool = MISSING, - exempt_roles: list[Snowflake] = MISSING, - exempt_channels: list[Snowflake] = MISSING, + name: str | utils.Undefined = MISSING, + event_type: AutoModEventType | utils.Undefined = MISSING, + trigger_metadata: AutoModTriggerMetadata | utils.Undefined = MISSING, + actions: list[AutoModAction] | utils.Undefined = MISSING, + enabled: bool | utils.Undefined = MISSING, + exempt_roles: list[Snowflake] | utils.Undefined = MISSING, + exempt_channels: list[Snowflake] | utils.Undefined = MISSING, reason: str | None = None, ) -> AutoModRule | None: """|coro| diff --git a/discord/channel.py b/discord/channel.py index 687baa5e5a..df0863cad1 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -389,7 +389,7 @@ async def purge( self, *, limit: int | None = 100, - check: Callable[[Message], bool] = MISSING, + check: Callable[[Message], bool] | utils.Undefined = MISSING, before: SnowflakeTime | None = None, after: SnowflakeTime | None = None, around: SnowflakeTime | None = None, @@ -864,7 +864,7 @@ async def create_thread( *, name: str, message: Snowflake | None = None, - auto_archive_duration: ThreadArchiveDuration = MISSING, + auto_archive_duration: ThreadArchiveDuration | utils.Undefined = MISSING, type: ChannelType | None = None, slowmode_delay: int | None = None, invitable: bool | None = None, @@ -1193,8 +1193,8 @@ async def create_thread( allowed_mentions=None, view=None, applied_tags=None, - auto_archive_duration: ThreadArchiveDuration = MISSING, - slowmode_delay: int = MISSING, + auto_archive_duration: ThreadArchiveDuration | utils.Undefined = MISSING, + slowmode_delay: int | utils.Undefined = MISSING, reason: str | None = None, ) -> Thread: """|coro| @@ -1868,7 +1868,7 @@ async def purge( self, *, limit: int | None = 100, - check: Callable[[Message], bool] = MISSING, + check: Callable[[Message], bool] | utils.Undefined = MISSING, before: SnowflakeTime | None = None, after: SnowflakeTime | None = None, around: SnowflakeTime | None = None, @@ -2418,7 +2418,7 @@ async def purge( self, *, limit: int | None = 100, - check: Callable[[Message], bool] = MISSING, + check: Callable[[Message], bool] | utils.Undefined = MISSING, before: SnowflakeTime | None = None, after: SnowflakeTime | None = None, around: SnowflakeTime | None = None, @@ -2599,7 +2599,7 @@ async def create_instance( self, *, topic: str, - privacy_level: StagePrivacyLevel = MISSING, + privacy_level: StagePrivacyLevel | utils.Undefined = MISSING, reason: str | None = None, send_notification: bool | None = False, ) -> StageInstance: diff --git a/discord/client.py b/discord/client.py index 6768d4a660..9d5b0cd83d 100644 --- a/discord/client.py +++ b/discord/client.py @@ -1246,7 +1246,7 @@ def _check(*args): return asyncio.wait_for(future, timeout) # event registration - def add_listener(self, func: Coro, name: str = MISSING) -> None: + def add_listener(self, func: Coro, name: str | utils.Undefined = MISSING) -> None: """The non decorator alternative to :meth:`.listen`. Parameters @@ -1293,7 +1293,7 @@ async def my_message(message): pass name, ) - def remove_listener(self, func: Coro, name: str = MISSING) -> None: + def remove_listener(self, func: Coro, name: str | utils.Undefined = MISSING) -> None: """Removes a listener from the pool of listeners. Parameters @@ -1313,7 +1313,7 @@ def remove_listener(self, func: Coro, name: str = MISSING) -> None: except ValueError: pass - def listen(self, name: str = MISSING, once: bool = False) -> Callable[[Coro], Coro]: + def listen(self, name: str | utils.Undefined = MISSING, once: bool = False) -> Callable[[Coro], Coro]: """A decorator that registers another function as an external event listener. Basically this allows you to listen to multiple events from different places e.g. such as :func:`.on_ready` @@ -1597,8 +1597,8 @@ async def create_guild( self, *, name: str, - icon: bytes = MISSING, - code: str = MISSING, + icon: bytes | utils.Undefined = MISSING, + code: str | utils.Undefined = MISSING, ) -> Guild: """|coro| diff --git a/discord/cog.py b/discord/cog.py index bf898d77da..b402e6f7c3 100644 --- a/discord/cog.py +++ b/discord/cog.py @@ -369,7 +369,7 @@ def _get_overridden_method(cls, method: FuncT) -> FuncT | None: @classmethod def listener( - cls, name: str = MISSING, once: bool = False + cls, name: str | discord.utils.Undefined = MISSING, once: bool = False ) -> Callable[[FuncT], FuncT]: """A decorator that marks a function as a listener. diff --git a/discord/commands/options.py b/discord/commands/options.py index 0c6b1fb6f3..2809602a70 100644 --- a/discord/commands/options.py +++ b/discord/commands/options.py @@ -44,7 +44,7 @@ from ..enums import ChannelType from ..enums import Enum as DiscordEnum from ..enums import SlashCommandOptionType -from ..utils import MISSING, basic_autocomplete +from ..utils import MISSING, Undefined, basic_autocomplete if TYPE_CHECKING: from ..ext.commands import Converter @@ -414,7 +414,7 @@ def __init__( self, name: str, value: str | int | float | None = None, - name_localizations: dict[str, str] = MISSING, + name_localizations: dict[str, str] | Undefined = MISSING, ): self.name = str(name) self.value = value if value is not None else name diff --git a/discord/components.py b/discord/components.py index c80eb5a57c..9ce6bfad7c 100644 --- a/discord/components.py +++ b/discord/components.py @@ -29,7 +29,7 @@ from .enums import ButtonStyle, ChannelType, ComponentType, InputTextStyle, try_enum from .partial_emoji import PartialEmoji, _EmojiTag -from .utils import MISSING, get_slots +from .utils import MISSING, Undefined, get_slots if TYPE_CHECKING: from .emoji import AppEmoji, GuildEmoji @@ -410,7 +410,7 @@ def __init__( self, *, label: str, - value: str = MISSING, + value: str | Undefined = MISSING, description: str | None = None, emoji: str | GuildEmoji | AppEmoji | PartialEmoji | None = None, default: bool = False, diff --git a/discord/emoji.py b/discord/emoji.py index 417751fce8..9324976f4d 100644 --- a/discord/emoji.py +++ b/discord/emoji.py @@ -30,7 +30,7 @@ from .asset import Asset, AssetMixin from .partial_emoji import PartialEmoji, _EmojiTag from .user import User -from .utils import MISSING, SnowflakeList, snowflake_time +from .utils import MISSING, SnowflakeList, Undefined, snowflake_time __all__ = ( "Emoji", @@ -234,8 +234,8 @@ async def delete(self, *, reason: str | None = None) -> None: async def edit( self, *, - name: str = MISSING, - roles: list[Snowflake] = MISSING, + name: str | Undefined = MISSING, + roles: list[Snowflake] | Undefined = MISSING, reason: str | None = None, ) -> GuildEmoji: r"""|coro| @@ -383,7 +383,7 @@ async def delete(self) -> None: async def edit( self, *, - name: str = MISSING, + name: str | Undefined = MISSING, ) -> AppEmoji: r"""|coro| diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index d348b6c536..149d054b78 100644 --- a/discord/ext/commands/bot.py +++ b/discord/ext/commands/bot.py @@ -32,6 +32,7 @@ from typing import TYPE_CHECKING, Any, Callable, Coroutine, Iterable, TypeVar import discord +from discord.utils import Undefined from . import errors from .context import Context @@ -123,7 +124,7 @@ def __init__( str | Iterable[str] | Coroutine[Any, Any, str | Iterable[str]], ] ) = when_mentioned, - help_command: HelpCommand | None = MISSING, + help_command: HelpCommand | None | Undefined = MISSING, **options, ): super().__init__(**options) diff --git a/discord/ext/commands/context.py b/discord/ext/commands/context.py index c140586faa..4b85ea8903 100644 --- a/discord/ext/commands/context.py +++ b/discord/ext/commands/context.py @@ -125,12 +125,12 @@ def __init__( message: Message, bot: BotT, view: StringView, - args: list[Any] = MISSING, - kwargs: dict[str, Any] = MISSING, + args: list[Any] | discord.utils.Undefined = MISSING, + kwargs: dict[str, Any] | discord.utils.Undefined = MISSING, prefix: str | None = None, command: Command | None = None, invoked_with: str | None = None, - invoked_parents: list[str] = MISSING, + invoked_parents: list[str] | discord.utils.Undefined = MISSING, invoked_subcommand: Command | None = None, subcommand_passed: str | None = None, command_failed: bool = False, diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 6f6ef1dffa..24f2973724 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -43,6 +43,8 @@ ) import discord +from discord import utils +from discord.utils import Undefined from ...commands import ( ApplicationCommand, @@ -1410,8 +1412,8 @@ def command( def command( self, - name: str = MISSING, - cls: type[CommandT] = MISSING, + name: str | Undefined = MISSING, + cls: type[CommandT] | Undefined = MISSING, *args: Any, **kwargs: Any, ) -> Callable[[Callable[Concatenate[ContextT, P], Coro[Any]]], CommandT]: @@ -1460,8 +1462,8 @@ def group( def group( self, - name: str = MISSING, - cls: type[GroupT] = MISSING, + name: str | Undefined = MISSING, + cls: type[GroupT] | Undefined = MISSING, *args: Any, **kwargs: Any, ) -> Callable[[Callable[Concatenate[ContextT, P], Coro[Any]]], GroupT]: @@ -1649,7 +1651,7 @@ def command( def command( - name: str = MISSING, cls: type[CommandT] = MISSING, **attrs: Any + name: str | utils.Undefined = MISSING, cls: type[CommandT] | utils.Undefined = MISSING, **attrs: Any ) -> Callable[ [ ( @@ -1737,8 +1739,8 @@ def group( def group( - name: str = MISSING, - cls: type[GroupT] = MISSING, + name: str | utils.Undefined = MISSING, + cls: type[GroupT] | utils.Undefined = MISSING, **attrs: Any, ) -> Callable[ [ diff --git a/discord/ext/commands/flags.py b/discord/ext/commands/flags.py index 54e7e0c37c..a8bc9aa7bc 100644 --- a/discord/ext/commands/flags.py +++ b/discord/ext/commands/flags.py @@ -31,12 +31,8 @@ from dataclasses import dataclass, field from typing import TYPE_CHECKING, Any, Iterator, Literal, Pattern, TypeVar, Union -from discord.utils import MISSING, MissingField, maybe_coroutine, resolve_annotation - -if sys.version_info >= (3, 11): - _MISSING = MissingField -else: - _MISSING = MISSING +from discord import utils +from discord.utils import MISSING, Undefined, maybe_coroutine, resolve_annotation from .converter import run_converters from .errors import ( @@ -86,13 +82,13 @@ class Flag: Whether multiple given values overrides the previous value. """ - name: str = _MISSING + name: str | Undefined = MISSING aliases: list[str] = field(default_factory=list) - attribute: str = _MISSING - annotation: Any = _MISSING - default: Any = _MISSING - max_args: int = _MISSING - override: bool = _MISSING + attribute: str | Undefined = MISSING + annotation: Any | Undefined = MISSING + default: Any | Undefined = MISSING + max_args: int | Undefined = MISSING + override: bool | Undefined = MISSING cast_to_dict: bool = False @property @@ -106,11 +102,11 @@ def required(self) -> bool: def flag( *, - name: str = MISSING, - aliases: list[str] = MISSING, + name: str | utils.Undefined = MISSING, + aliases: list[str] | utils.Undefined = MISSING, default: Any = MISSING, - max_args: int = MISSING, - override: bool = MISSING, + max_args: int | utils.Undefined = MISSING, + override: bool | utils.Undefined = MISSING, ) -> Any: """Override default functionality and parameters of the underlying :class:`FlagConverter` class attributes. @@ -284,9 +280,9 @@ def __new__( bases: tuple[type, ...], attrs: dict[str, Any], *, - case_insensitive: bool = MISSING, - delimiter: str = MISSING, - prefix: str = MISSING, + case_insensitive: bool | utils.Undefined = MISSING, + delimiter: str | utils.Undefined = MISSING, + prefix: str | utils.Undefined = MISSING, ): attrs["__commands_is_flag__"] = True diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index af34cc6844..63af87d162 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -36,6 +36,7 @@ import aiohttp import discord +from discord import utils from discord.backoff import ExponentialBackoff from discord.utils import MISSING @@ -97,8 +98,8 @@ def __init__( self.loop: asyncio.AbstractEventLoop = loop self.count: int | None = count self._current_loop = 0 - self._handle: SleepHandle = MISSING - self._task: asyncio.Task[None] = MISSING + self._handle: SleepHandle | utils.Undefined = MISSING + self._task: asyncio.Task[None] | utils.Undefined = MISSING self._injected = None self._valid_exception = ( OSError, @@ -121,7 +122,7 @@ def __init__( self.change_interval(seconds=seconds, minutes=minutes, hours=hours, time=time) self._last_iteration_failed = False - self._last_iteration: datetime.datetime = MISSING + self._last_iteration: datetime.datetime | utils.Undefined = MISSING self._next_iteration = None if not inspect.iscoroutinefunction(self.coro): @@ -611,7 +612,7 @@ def _get_next_sleep_time(self) -> datetime.datetime: self._time_index += 1 return datetime.datetime.combine(next_date, next_time) - def _prepare_time_index(self, now: datetime.datetime = MISSING) -> None: + def _prepare_time_index(self, now: datetime.datetime | utils.Undefined = MISSING) -> None: # now kwarg should be a datetime.datetime representing the time "now" # to calculate the next time index from @@ -663,7 +664,7 @@ def change_interval( seconds: float = 0, minutes: float = 0, hours: float = 0, - time: datetime.time | Sequence[datetime.time] = MISSING, + time: datetime.time | Sequence[datetime.time] | utils.Undefined = MISSING, ) -> None: """Changes the interval for the sleep time. @@ -709,7 +710,7 @@ def change_interval( self._seconds = float(seconds) self._hours = float(hours) self._minutes = float(minutes) - self._time: list[datetime.time] = MISSING + self._time: list[datetime.time] | utils.Undefined = MISSING else: if any((seconds, minutes, hours)): raise TypeError("Cannot mix explicit time with relative time") @@ -731,13 +732,13 @@ def change_interval( def loop( *, - seconds: float = MISSING, - minutes: float = MISSING, - hours: float = MISSING, - time: datetime.time | Sequence[datetime.time] = MISSING, + seconds: float | utils.Undefined = MISSING, + minutes: float | utils.Undefined = MISSING, + hours: float | utils.Undefined = MISSING, + time: datetime.time | Sequence[datetime.time] | utils.Undefined = MISSING, count: int | None = None, reconnect: bool = True, - loop: asyncio.AbstractEventLoop = MISSING, + loop: asyncio.AbstractEventLoop | utils.Undefined = MISSING, ) -> Callable[[LF], Loop[LF]]: """A decorator that schedules a task in the background for you with optional reconnect logic. The decorator returns a :class:`Loop`. diff --git a/discord/guild.py b/discord/guild.py index 337abd31c0..4832e02087 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -1079,7 +1079,7 @@ def _create_channel( self, name: str, channel_type: ChannelType, - overwrites: dict[Role | Member, PermissionOverwrite] = MISSING, + overwrites: dict[Role | Member, PermissionOverwrite] | utils.Undefined = MISSING, category: Snowflake | None = None, **options: Any, ): @@ -1125,11 +1125,11 @@ async def create_text_channel( *, reason: str | None = None, category: CategoryChannel | None = None, - position: int = MISSING, - topic: str = MISSING, - slowmode_delay: int = MISSING, - nsfw: bool = MISSING, - overwrites: dict[Role | Member, PermissionOverwrite] = MISSING, + position: int | utils.Undefined = MISSING, + topic: str | utils.Undefined = MISSING, + slowmode_delay: int | utils.Undefined = MISSING, + nsfw: bool | utils.Undefined = MISSING, + overwrites: dict[Role | Member, PermissionOverwrite] | utils.Undefined = MISSING, ) -> TextChannel: """|coro| @@ -1240,12 +1240,12 @@ async def create_voice_channel( *, reason: str | None = None, category: CategoryChannel | None = None, - position: int = MISSING, - bitrate: int = MISSING, - user_limit: int = MISSING, - rtc_region: VoiceRegion | None = MISSING, - video_quality_mode: VideoQualityMode = MISSING, - overwrites: dict[Role | Member, PermissionOverwrite] = MISSING, + position: int | utils.Undefined = MISSING, + bitrate: int | utils.Undefined = MISSING, + user_limit: int | utils.Undefined = MISSING, + rtc_region: VoiceRegion | None | utils.Undefined = MISSING, + video_quality_mode: VideoQualityMode | utils.Undefined = MISSING, + overwrites: dict[Role | Member, PermissionOverwrite] | utils.Undefined = MISSING, ) -> VoiceChannel: """|coro| @@ -1329,8 +1329,8 @@ async def create_stage_channel( name: str, *, topic: str, - position: int = MISSING, - overwrites: dict[Role | Member, PermissionOverwrite] = MISSING, + position: int | utils.Undefined = MISSING, + overwrites: dict[Role | Member, PermissionOverwrite] | utils.Undefined = MISSING, category: CategoryChannel | None = None, reason: str | None = None, ) -> StageChannel: @@ -1399,12 +1399,12 @@ async def create_forum_channel( *, reason: str | None = None, category: CategoryChannel | None = None, - position: int = MISSING, - topic: str = MISSING, - slowmode_delay: int = MISSING, - nsfw: bool = MISSING, - overwrites: dict[Role | Member, PermissionOverwrite] = MISSING, - default_reaction_emoji: GuildEmoji | int | str = MISSING, + position: int | utils.Undefined = MISSING, + topic: str | utils.Undefined = MISSING, + slowmode_delay: int | utils.Undefined = MISSING, + nsfw: bool | utils.Undefined = MISSING, + overwrites: dict[Role | Member, PermissionOverwrite] | utils.Undefined = MISSING, + default_reaction_emoji: GuildEmoji | int | str | utils.Undefined = MISSING, ) -> ForumChannel: """|coro| @@ -1539,9 +1539,9 @@ async def create_category( self, name: str, *, - overwrites: dict[Role | Member, PermissionOverwrite] = MISSING, + overwrites: dict[Role | Member, PermissionOverwrite] | utils.Undefined = MISSING, reason: str | None = None, - position: int = MISSING, + position: int | utils.Undefined = MISSING, ) -> CategoryChannel: """|coro| @@ -1642,27 +1642,27 @@ async def set_mfa_required(self, required: bool, *, reason: str = None) -> None: async def edit( self, *, - reason: str | None = MISSING, - name: str = MISSING, - description: str | None = MISSING, - icon: bytes | None = MISSING, - banner: bytes | None = MISSING, + reason: str | None | utils.Undefined = MISSING, + name: str | utils.Undefined = MISSING, + description: str | None | utils.Undefined = MISSING, + icon: bytes | None | utils.Undefined = MISSING, + banner: bytes | None | utils.Undefined = MISSING, splash: bytes | None = MISSING, - discovery_splash: bytes | None = MISSING, - community: bool = MISSING, - afk_channel: VoiceChannel | None = MISSING, - owner: Snowflake = MISSING, - afk_timeout: int = MISSING, - default_notifications: NotificationLevel = MISSING, - verification_level: VerificationLevel = MISSING, - explicit_content_filter: ContentFilter = MISSING, - system_channel: TextChannel | None = MISSING, - system_channel_flags: SystemChannelFlags = MISSING, - preferred_locale: str = MISSING, - rules_channel: TextChannel | None = MISSING, - public_updates_channel: TextChannel | None = MISSING, - premium_progress_bar_enabled: bool = MISSING, - disable_invites: bool = MISSING, + discovery_splash: bytes | None | utils.Undefined = MISSING, + community: bool | utils.Undefined = MISSING, + afk_channel: VoiceChannel | None | utils.Undefined = MISSING, + owner: Snowflake | utils.Undefined = MISSING, + afk_timeout: int | utils.Undefined = MISSING, + default_notifications: NotificationLevel | utils.Undefined = MISSING, + verification_level: VerificationLevel | utils.Undefined = MISSING, + explicit_content_filter: ContentFilter | utils.Undefined = MISSING, + system_channel: TextChannel | None | utils.Undefined = MISSING, + system_channel_flags: SystemChannelFlags | utils.Undefined = MISSING, + preferred_locale: str | utils.Undefined = MISSING, + rules_channel: TextChannel | None | utils.Undefined = MISSING, + public_updates_channel: TextChannel | None | utils.Undefined = MISSING, + premium_progress_bar_enabled: bool | utils.Undefined = MISSING, + disable_invites: bool | utils.Undefined = MISSING, ) -> Guild: r"""|coro| @@ -2231,7 +2231,7 @@ async def prune_members( *, days: int, compute_prune_count: bool = True, - roles: list[Snowflake] = MISSING, + roles: list[Snowflake] | utils.Undefined = MISSING, reason: str | None = None, ) -> int | None: r"""|coro| @@ -2347,7 +2347,7 @@ async def webhooks(self) -> list[Webhook]: return [Webhook.from_state(d, state=self._state) for d in data] async def estimate_pruned_members( - self, *, days: int, roles: list[Snowflake] = MISSING + self, *, days: int, roles: list[Snowflake] | utils.Undefined = MISSING ) -> int: """|coro| @@ -2422,7 +2422,7 @@ async def invites(self) -> list[Invite]: return result async def create_template( - self, *, name: str, description: str = MISSING + self, *, name: str, description: str | utils.Undefined = MISSING ) -> Template: """|coro| @@ -2721,7 +2721,7 @@ async def create_custom_emoji( *, name: str, image: bytes, - roles: list[Role] = MISSING, + roles: list[Role] | utils.Undefined = MISSING, reason: str | None = None, ) -> GuildEmoji: r"""|coro| @@ -2883,8 +2883,8 @@ async def create_role( colour: Colour | int = ..., hoist: bool = ..., mentionable: bool = ..., - icon: bytes | None = MISSING, - unicode_emoji: str | None = MISSING, + icon: bytes | None | utils.Undefined = MISSING, + unicode_emoji: str | None | utils.Undefined = MISSING, ) -> Role: ... @overload @@ -2904,15 +2904,15 @@ async def create_role( async def create_role( self, *, - name: str = MISSING, - permissions: Permissions = MISSING, - color: Colour | int = MISSING, - colour: Colour | int = MISSING, - hoist: bool = MISSING, - mentionable: bool = MISSING, + name: str | utils.Undefined = MISSING, + permissions: Permissions | utils.Undefined = MISSING, + color: Colour | int | utils.Undefined = MISSING, + colour: Colour | int | utils.Undefined = MISSING, + hoist: bool | utils.Undefined = MISSING, + mentionable: bool | utils.Undefined = MISSING, reason: str | None = None, - icon: bytes | None = MISSING, - unicode_emoji: str | None = MISSING, + icon: bytes | None | utils.Undefined = MISSING, + unicode_emoji: str | None | utils.Undefined = MISSING, ) -> Role: """|coro| @@ -3382,7 +3382,7 @@ async def widget(self) -> Widget: return Widget(state=self._state, data=data) async def edit_widget( - self, *, enabled: bool = MISSING, channel: Snowflake | None = MISSING + self, *, enabled: bool | utils.Undefined = MISSING, channel: Snowflake | None | utils.Undefined = MISSING ) -> None: """|coro| @@ -3769,13 +3769,13 @@ async def create_scheduled_event( self, *, name: str, - description: str = MISSING, + description: str | utils.Undefined = MISSING, start_time: datetime, - end_time: datetime = MISSING, + end_time: datetime | utils.Undefined = MISSING, location: str | int | VoiceChannel | StageChannel | ScheduledEventLocation, privacy_level: ScheduledEventPrivacyLevel = ScheduledEventPrivacyLevel.guild_only, reason: str | None = None, - image: bytes = MISSING, + image: bytes | utils.Undefined = MISSING, ) -> ScheduledEvent | None: """|coro| Creates a scheduled event. @@ -3986,11 +3986,11 @@ async def onboarding(self): async def edit_onboarding( self, *, - prompts: list[OnboardingPrompt] | None = MISSING, - default_channels: list[Snowflake] | None = MISSING, - enabled: bool | None = MISSING, - mode: OnboardingMode | None = MISSING, - reason: str | None = MISSING, + prompts: list[OnboardingPrompt] | None | utils.Undefined = MISSING, + default_channels: list[Snowflake] | None | utils.Undefined = MISSING, + enabled: bool | None | utils.Undefined = MISSING, + mode: OnboardingMode | None | utils.Undefined = MISSING, + reason: str | None | utils.Undefined = MISSING, ) -> Onboarding: """|coro| diff --git a/discord/http.py b/discord/http.py index 2db704b268..45528ffe9b 100644 --- a/discord/http.py +++ b/discord/http.py @@ -179,7 +179,7 @@ def __init__( asyncio.get_event_loop() if loop is None else loop ) self.connector = connector - self.__session: aiohttp.ClientSession = MISSING # filled in static_login + self.__session: aiohttp.ClientSession | utils.Undefined = MISSING # filled in static_login self._locks: weakref.WeakValueDictionary = weakref.WeakValueDictionary() self._global_over: asyncio.Event = asyncio.Event() self._global_over.set() diff --git a/discord/integrations.py b/discord/integrations.py index 60ecbdde3f..03da425dc2 100644 --- a/discord/integrations.py +++ b/discord/integrations.py @@ -32,6 +32,7 @@ from .errors import InvalidArgument from .user import User from .utils import MISSING, _get_as_snowflake, parse_time +from discord import utils __all__ = ( "IntegrationAccount", @@ -226,9 +227,9 @@ def role(self) -> Role | None: async def edit( self, *, - expire_behaviour: ExpireBehaviour = MISSING, - expire_grace_period: int = MISSING, - enable_emoticons: bool = MISSING, + expire_behaviour: ExpireBehaviour | utils.Undefined = MISSING, + expire_grace_period: int | utils.Undefined = MISSING, + enable_emoticons: bool | utils.Undefined = MISSING, ) -> None: """|coro| diff --git a/discord/interactions.py b/discord/interactions.py index 57628f4691..0b56e95a5e 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -472,13 +472,13 @@ async def original_message(self): async def edit_original_response( self, *, - content: str | None = MISSING, - embeds: list[Embed] = MISSING, - embed: Embed | None = MISSING, - file: File = MISSING, - files: list[File] = MISSING, - attachments: list[Attachment] = MISSING, - view: View | None = MISSING, + content: str | None | utils.Undefined = MISSING, + embeds: list[Embed] | utils.Undefined = MISSING, + embed: Embed | None | utils.Undefined = MISSING, + file: File | utils.Undefined = MISSING, + files: list[File] | utils.Undefined = MISSING, + attachments: list[Attachment] | utils.Undefined = MISSING, + view: View | None | utils.Undefined = MISSING, allowed_mentions: AllowedMentions | None = None, delete_after: float | None = None, suppress: bool = False, @@ -1039,15 +1039,15 @@ async def send_message( async def edit_message( self, *, - content: Any | None = MISSING, - embed: Embed | None = MISSING, - embeds: list[Embed] = MISSING, - file: File = MISSING, - files: list[File] = MISSING, - attachments: list[Attachment] = MISSING, - view: View | None = MISSING, + content: Any | None | utils.Undefined = MISSING, + embed: Embed | None | utils.Undefined = MISSING, + embeds: list[Embed] | utils.Undefined = MISSING, + file: File | utils.Undefined = MISSING, + files: list[File] | utils.Undefined = MISSING, + attachments: list[Attachment] | utils.Undefined = MISSING, + view: View | None | utils.Undefined = MISSING, delete_after: float | None = None, - suppress: bool | None = MISSING, + suppress: bool | None | utils.Undefined = MISSING, allowed_mentions: AllowedMentions | None = None, ) -> None: """|coro| @@ -1382,16 +1382,16 @@ class InteractionMessage(Message): async def edit( self, - content: str | None = MISSING, - embeds: list[Embed] = MISSING, - embed: Embed | None = MISSING, - file: File = MISSING, - files: list[File] = MISSING, - attachments: list[Attachment] = MISSING, - view: View | None = MISSING, + content: str | None | utils.Undefined = MISSING, + embeds: list[Embed] | utils.Undefined = MISSING, + embed: Embed | None | utils.Undefined = MISSING, + file: File | utils.Undefined = MISSING, + files: list[File] | utils.Undefined = MISSING, + attachments: list[Attachment] | utils.Undefined = MISSING, + view: View | None | utils.Undefined = MISSING, allowed_mentions: AllowedMentions | None = None, delete_after: float | None = None, - suppress: bool | None = MISSING, + suppress: bool | None | utils.Undefined = MISSING, ) -> InteractionMessage: """|coro| diff --git a/discord/member.py b/discord/member.py index 0ff90cce04..0e0de392f6 100644 --- a/discord/member.py +++ b/discord/member.py @@ -760,15 +760,15 @@ async def kick(self, *, reason: str | None = None) -> None: async def edit( self, *, - nick: str | None = MISSING, - mute: bool = MISSING, - deafen: bool = MISSING, - suppress: bool = MISSING, - roles: list[discord.abc.Snowflake] = MISSING, - voice_channel: VocalGuildChannel | None = MISSING, + nick: str | None | utils.Undefined = MISSING, + mute: bool | utils.Undefined = MISSING, + deafen: bool | utils.Undefined = MISSING, + suppress: bool | utils.Undefined = MISSING, + roles: list[discord.abc.Snowflake] | utils.Undefined = MISSING, + voice_channel: VocalGuildChannel | None | utils.Undefined = MISSING, reason: str | None = None, - communication_disabled_until: datetime.datetime | None = MISSING, - bypass_verification: bool | None = MISSING, + communication_disabled_until: datetime.datetime | None | utils.Undefined = MISSING, + bypass_verification: bool | None | utils.Undefined = MISSING, ) -> Member | None: """|coro| diff --git a/discord/message.py b/discord/message.py index 55a6bfd6b4..29be44769c 100644 --- a/discord/message.py +++ b/discord/message.py @@ -1486,16 +1486,16 @@ async def edit( async def edit( self, - content: str | None = MISSING, - embed: Embed | None = MISSING, - embeds: list[Embed] = MISSING, - file: Sequence[File] = MISSING, - files: list[Sequence[File]] = MISSING, - attachments: list[Attachment] = MISSING, - suppress: bool = MISSING, + content: str | None | utils.Undefined = MISSING, + embed: Embed | None | utils.Undefined = MISSING, + embeds: list[Embed] | utils.Undefined = MISSING, + file: Sequence[File] | utils.Undefined = MISSING, + files: list[Sequence[File]] | utils.Undefined = MISSING, + attachments: list[Attachment] | utils.Undefined = MISSING, + suppress: bool | utils.Undefined = MISSING, delete_after: float | None = None, - allowed_mentions: AllowedMentions | None = MISSING, - view: View | None = MISSING, + allowed_mentions: AllowedMentions | None | utils.Undefined = MISSING, + view: View | None | utils.Undefined = MISSING, ) -> Message: """|coro| @@ -1847,8 +1847,8 @@ async def create_thread( self, *, name: str, - auto_archive_duration: ThreadArchiveDuration = MISSING, - slowmode_delay: int = MISSING, + auto_archive_duration: ThreadArchiveDuration | utils.Undefined = MISSING, + slowmode_delay: int | utils.Undefined = MISSING, ) -> Thread: """|coro| diff --git a/discord/onboarding.py b/discord/onboarding.py index cf6a721a00..b82de31cfc 100644 --- a/discord/onboarding.py +++ b/discord/onboarding.py @@ -29,6 +29,7 @@ from .enums import OnboardingMode, PromptType, try_enum from .partial_emoji import PartialEmoji from .utils import MISSING, cached_property, generate_snowflake, get +from discord import utils if TYPE_CHECKING: from .abc import Snowflake @@ -266,11 +267,11 @@ def default_channels( async def edit( self, *, - prompts: list[OnboardingPrompt] | None = MISSING, - default_channels: list[Snowflake] | None = MISSING, - enabled: bool | None = MISSING, - mode: OnboardingMode | None = MISSING, - reason: str | None = MISSING, + prompts: list[OnboardingPrompt] | None | utils.Undefined = MISSING, + default_channels: list[Snowflake] | None | utils.Undefined = MISSING, + enabled: bool | None | utils.Undefined = MISSING, + mode: OnboardingMode | None | utils.Undefined = MISSING, + reason: str | None | utils.Undefined = MISSING, ) -> Onboarding: """|coro| @@ -442,7 +443,7 @@ async def delete_prompt( self, id: int, *, - reason: str | None = MISSING, + reason: str | None | utils.Undefined = MISSING, ): """|coro| diff --git a/discord/player.py b/discord/player.py index 65b23ed42a..8093ab13c0 100644 --- a/discord/player.py +++ b/discord/player.py @@ -43,7 +43,7 @@ from .errors import ClientException from .oggparse import OggStream from .opus import Encoder as OpusEncoder -from .utils import MISSING +from .utils import MISSING, Undefined if TYPE_CHECKING: from .voice_client import VoiceClient @@ -164,7 +164,7 @@ def __init__( kwargs = {"stdout": subprocess.PIPE} kwargs.update(subprocess_kwargs) - self._process: subprocess.Popen = self._spawn_process(args, **kwargs) + self._process: subprocess.Popen | Undefined = self._spawn_process(args, **kwargs) self._stdout: IO[bytes] = self._process.stdout # type: ignore self._stdin: IO[bytes] | None = None self._pipe_thread: threading.Thread | None = None diff --git a/discord/role.py b/discord/role.py index 1d7777a903..717df727bb 100644 --- a/discord/role.py +++ b/discord/role.py @@ -25,6 +25,7 @@ from __future__ import annotations +from email import utils from typing import TYPE_CHECKING, Any, TypeVar from .asset import Asset @@ -448,16 +449,16 @@ async def _move(self, position: int, reason: str | None) -> None: async def edit( self, *, - name: str = MISSING, - permissions: Permissions = MISSING, - colour: Colour | int = MISSING, - color: Colour | int = MISSING, - hoist: bool = MISSING, - mentionable: bool = MISSING, - position: int = MISSING, - reason: str | None = MISSING, - icon: bytes | None = MISSING, - unicode_emoji: str | None = MISSING, + name: str | utils.Undefined = MISSING, + permissions: Permissions | utils.Undefined = MISSING, + colour: Colour | int | utils.Undefined = MISSING, + color: Colour | int | utils.Undefined = MISSING, + hoist: bool | utils.Undefined = MISSING, + mentionable: bool | utils.Undefined = MISSING, + position: int | utils.Undefined = MISSING, + reason: str | None | utils.Undefined = MISSING, + icon: bytes | None | utils.Undefined = MISSING, + unicode_emoji: str | None | utils.Undefined = MISSING, ) -> Role | None: """|coro| diff --git a/discord/scheduled_events.py b/discord/scheduled_events.py index 7e339dcee7..44d3fc9b0b 100644 --- a/discord/scheduled_events.py +++ b/discord/scheduled_events.py @@ -279,16 +279,16 @@ async def edit( self, *, reason: str | None = None, - name: str = MISSING, - description: str = MISSING, - status: int | ScheduledEventStatus = MISSING, + name: str | utils.Undefined = MISSING, + description: str | utils.Undefined = MISSING, + status: int | ScheduledEventStatus | utils.Undefined = MISSING, location: ( - str | int | VoiceChannel | StageChannel | ScheduledEventLocation + str | int | VoiceChannel | StageChannel | ScheduledEventLocation | utils.Undefined ) = MISSING, - start_time: datetime.datetime = MISSING, - end_time: datetime.datetime = MISSING, - cover: bytes | None = MISSING, - image: bytes | None = MISSING, + start_time: datetime.datetime | utils.Undefined = MISSING, + end_time: datetime.datetime | utils.Undefined = MISSING, + cover: bytes | None | utils.Undefined = MISSING, + image: bytes | None | utils.Undefined = MISSING, privacy_level: ScheduledEventPrivacyLevel = ScheduledEventPrivacyLevel.guild_only, ) -> ScheduledEvent | None: """|coro| @@ -375,7 +375,7 @@ async def edit( if location is not MISSING: if not isinstance( - location, (ScheduledEventLocation, utils._MissingSentinel) + location, (ScheduledEventLocation, utils.Undefined) ): location = ScheduledEventLocation(state=self._state, value=location) diff --git a/discord/stage_instance.py b/discord/stage_instance.py index 8864a2f59a..762dc5ef03 100644 --- a/discord/stage_instance.py +++ b/discord/stage_instance.py @@ -30,7 +30,7 @@ from .enums import StagePrivacyLevel, try_enum from .errors import InvalidArgument from .mixins import Hashable -from .utils import MISSING, cached_slot_property +from .utils import MISSING, Undefined, cached_slot_property __all__ = ("StageInstance",) @@ -128,8 +128,8 @@ def is_public(self) -> bool: async def edit( self, *, - topic: str = MISSING, - privacy_level: StagePrivacyLevel = MISSING, + topic: str | Undefined = MISSING, + privacy_level: StagePrivacyLevel | Undefined = MISSING, reason: str | None = None, ) -> None: """|coro| diff --git a/discord/sticker.py b/discord/sticker.py index d204c4b369..f70cbd2709 100644 --- a/discord/sticker.py +++ b/discord/sticker.py @@ -32,7 +32,7 @@ from .enums import StickerFormatType, StickerType, try_enum from .errors import InvalidData from .mixins import Hashable -from .utils import MISSING, cached_slot_property, find, get, snowflake_time +from .utils import MISSING, Undefined, cached_slot_property, find, get, snowflake_time __all__ = ( "StickerPack", @@ -454,9 +454,9 @@ def guild(self) -> Guild | None: async def edit( self, *, - name: str = MISSING, - description: str = MISSING, - emoji: str = MISSING, + name: str | Undefined = MISSING, + description: str | Undefined = MISSING, + emoji: str | Undefined = MISSING, reason: str | None = None, ) -> GuildSticker: """|coro| diff --git a/discord/template.py b/discord/template.py index 74455a1727..0f40963b2b 100644 --- a/discord/template.py +++ b/discord/template.py @@ -28,7 +28,7 @@ from typing import TYPE_CHECKING, Any from .guild import Guild -from .utils import MISSING, _bytes_to_base64_data, parse_time +from .utils import MISSING, Undefined, _bytes_to_base64_data, parse_time __all__ = ("Template",) @@ -236,8 +236,8 @@ async def sync(self) -> Template: async def edit( self, *, - name: str = MISSING, - description: str | None = MISSING, + name: str | Undefined = MISSING, + description: str | None | Undefined = MISSING, ) -> Template: """|coro| diff --git a/discord/threads.py b/discord/threads.py index 0e1675a1bd..5caa4c1f96 100644 --- a/discord/threads.py +++ b/discord/threads.py @@ -33,6 +33,7 @@ from .flags import ChannelFlags from .mixins import Hashable from .utils import MISSING, _get_as_snowflake, parse_time +from discord import utils __all__ = ( "Thread", @@ -517,7 +518,7 @@ async def purge( self, *, limit: int | None = 100, - check: Callable[[Message], bool] = MISSING, + check: Callable[[Message], bool] | utils.Undefined = MISSING, before: SnowflakeTime | None = None, after: SnowflakeTime | None = None, around: SnowflakeTime | None = None, @@ -597,14 +598,14 @@ def is_me(m): async def edit( self, *, - name: str = MISSING, - archived: bool = MISSING, - locked: bool = MISSING, - invitable: bool = MISSING, - slowmode_delay: int = MISSING, - auto_archive_duration: ThreadArchiveDuration = MISSING, - pinned: bool = MISSING, - applied_tags: list[ForumTag] = MISSING, + name: str | utils.Undefined = MISSING, + archived: bool | utils.Undefined = MISSING, + locked: bool | utils.Undefined = MISSING, + invitable: bool | utils.Undefined = MISSING, + slowmode_delay: int | utils.Undefined = MISSING, + auto_archive_duration: ThreadArchiveDuration | utils.Undefined = MISSING, + pinned: bool | utils.Undefined = MISSING, + applied_tags: list[ForumTag] | utils.Undefined = MISSING, reason: str | None = None, ) -> Thread: """|coro| @@ -681,7 +682,7 @@ async def edit( # The data payload will always be a Thread payload return Thread(data=data, state=self._state, guild=self.guild) # type: ignore - async def archive(self, locked: bool = MISSING) -> Thread: + async def archive(self, locked: bool | utils.Undefined = MISSING) -> Thread: """|coro| Archives the thread. This is a shorthand of :meth:`.edit`. diff --git a/discord/ui/select.py b/discord/ui/select.py index 35785890b5..d9b07e0ece 100644 --- a/discord/ui/select.py +++ b/discord/ui/select.py @@ -42,6 +42,7 @@ from ..user import User from ..utils import MISSING from .item import Item, ItemCallbackType +from discord import utils __all__ = ( "Select", @@ -258,7 +259,7 @@ def add_option( self, *, label: str, - value: str = MISSING, + value: str | utils.Undefined = MISSING, description: str | None = None, emoji: str | GuildEmoji | AppEmoji | PartialEmoji | None = None, default: bool = False, @@ -453,8 +454,8 @@ def select( custom_id: str | None = None, min_values: int = 1, max_values: int = 1, - options: list[SelectOption] = MISSING, - channel_types: list[ChannelType] = MISSING, + options: list[SelectOption] | utils.Undefined = MISSING, + channel_types: list[ChannelType] | utils.Undefined = MISSING, disabled: bool = False, row: int | None = None, ) -> Callable[[ItemCallbackType], ItemCallbackType]: @@ -551,7 +552,7 @@ def string_select( custom_id: str | None = None, min_values: int = 1, max_values: int = 1, - options: list[SelectOption] = MISSING, + options: list[SelectOption] | utils.Undefined = MISSING, disabled: bool = False, row: int | None = None, ) -> Callable[[ItemCallbackType], ItemCallbackType]: @@ -650,7 +651,7 @@ def channel_select( min_values: int = 1, max_values: int = 1, disabled: bool = False, - channel_types: list[ChannelType] = MISSING, + channel_types: list[ChannelType] | utils.Undefined = MISSING, row: int | None = None, ) -> Callable[[ItemCallbackType], ItemCallbackType]: """A shortcut for :meth:`discord.ui.select` with select type :attr:`discord.ComponentType.channel_select`. diff --git a/discord/user.py b/discord/user.py index 9fa995cf66..0de9efe5a5 100644 --- a/discord/user.py +++ b/discord/user.py @@ -34,7 +34,7 @@ from .flags import PublicUserFlags from .iterators import EntitlementIterator from .monetization import Entitlement -from .utils import MISSING, _bytes_to_base64_data, snowflake_time +from .utils import MISSING, Undefined, _bytes_to_base64_data, snowflake_time if TYPE_CHECKING: from datetime import datetime @@ -429,9 +429,9 @@ def _update(self, data: UserPayload) -> None: async def edit( self, *, - username: str = MISSING, - avatar: bytes = MISSING, - banner: bytes = MISSING, + username: str | Undefined = MISSING, + avatar: bytes | Undefined = MISSING, + banner: bytes | Undefined = MISSING, ) -> ClientUser: """|coro| diff --git a/discord/utils.py b/discord/utils.py index 363d339391..5dea905617 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -29,6 +29,7 @@ import asyncio import collections.abc import datetime +from enum import Enum, auto import functools import itertools import json @@ -103,24 +104,14 @@ DISCORD_EPOCH = 1420070400000 -class _MissingSentinel: - def __eq__(self, other) -> bool: - return False +class Undefined(Enum): + MISSING = auto() - def __bool__(self) -> bool: + def __bool__(self) -> Literal[False]: return False - def __repr__(self) -> str: - return "..." - - -MISSING: Any = _MissingSentinel() -# As of 3.11, directly setting a dataclass field to MISSING causes a ValueError. Using -# field(default=MISSING) produces the same error, but passing a lambda to -# default_factory produces the same behavior as default=MISSING and does not raise an -# error. -MissingField = field(default_factory=lambda: MISSING) +MISSING: Literal[Undefined.MISSING] = Undefined.MISSING class _cached_property: def __init__(self, function): @@ -388,10 +379,10 @@ def decorated(*args: P.args, **kwargs: P.kwargs) -> T: def oauth_url( client_id: int | str, *, - permissions: Permissions = MISSING, - guild: Snowflake = MISSING, - redirect_uri: str = MISSING, - scopes: Iterable[str] = MISSING, + permissions: Permissions | Undefined = MISSING, + guild: Snowflake | Undefined = MISSING, + redirect_uri: str | Undefined = MISSING, + scopes: Iterable[str] | Undefined = MISSING, disable_guild_select: bool = False, ) -> str: """A helper function that returns the OAuth2 URL for inviting the bot diff --git a/discord/voice_client.py b/discord/voice_client.py index 4ba571c9a7..cf6e5d0537 100644 --- a/discord/voice_client.py +++ b/discord/voice_client.py @@ -224,7 +224,7 @@ class VoiceClient(VoiceProtocol): or the library will not be able to transmit audio. """ - endpoint_ip: str + endpoint_ip: str | utils.Undefined voice_port: int secret_key: list[int] ssrc: int @@ -235,7 +235,7 @@ def __init__(self, client: Client, channel: abc.Connectable): super().__init__(client, channel) state = client._connection - self.token: str = MISSING + self.token: str | utils.Undefined = MISSING self.socket = MISSING self.loop: asyncio.AbstractEventLoop = state.loop self._state: ConnectionState = state @@ -247,17 +247,17 @@ def __init__(self, client: Client, channel: abc.Connectable): self._voice_state_complete: asyncio.Event = asyncio.Event() self._voice_server_complete: asyncio.Event = asyncio.Event() - self.mode: str = MISSING + self.mode: str | utils.Undefined = MISSING self._connections: int = 0 self.sequence: int = 0 self.timestamp: int = 0 self.timeout: float = 0 - self._runner: asyncio.Task = MISSING + self._runner: asyncio.Task | utils.Undefined = MISSING self._player: AudioPlayer | None = None - self.encoder: Encoder = MISSING + self.encoder: Encoder | utils.Undefined = MISSING self.decoder = None self._lite_nonce: int = 0 - self.ws: DiscordVoiceWebSocket = MISSING + self.ws: DiscordVoiceWebSocket | utils.Undefined = MISSING self.paused = False self.recording = False diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py index 1661b1bb67..61ac6391e3 100644 --- a/discord/webhook/async_.py +++ b/discord/webhook/async_.py @@ -616,21 +616,21 @@ class ExecuteWebhookParameters(NamedTuple): def handle_message_parameters( - content: str | None = MISSING, + content: str | None | utils.Undefined = MISSING, *, - username: str = MISSING, + username: str | utils.Undefined = MISSING, avatar_url: Any = MISSING, tts: bool = False, ephemeral: bool = False, - file: File = MISSING, - files: list[File] = MISSING, - attachments: list[Attachment] = MISSING, - embed: Embed | None = MISSING, - embeds: list[Embed] = MISSING, - view: View | None = MISSING, - poll: Poll | None = MISSING, - applied_tags: list[Snowflake] = MISSING, - allowed_mentions: AllowedMentions | None = MISSING, + file: File | utils.Undefined = MISSING, + files: list[File] | utils.Undefined = MISSING, + attachments: list[Attachment] | utils.Undefined = MISSING, + embed: Embed | None | utils.Undefined = MISSING, + embeds: list[Embed] | utils.Undefined = MISSING, + view: View | None | utils.Undefined = MISSING, + poll: Poll | None | utils.Undefined = MISSING, + applied_tags: list[Snowflake] | utils.Undefined = MISSING, + allowed_mentions: AllowedMentions | None | utils.Undefined = MISSING, previous_allowed_mentions: AllowedMentions | None = None, suppress: bool = False, ) -> ExecuteWebhookParameters: @@ -858,15 +858,15 @@ class WebhookMessage(Message): async def edit( self, - content: str | None = MISSING, - embeds: list[Embed] = MISSING, - embed: Embed | None = MISSING, - file: File = MISSING, - files: list[File] = MISSING, - attachments: list[Attachment] = MISSING, - view: View | None = MISSING, + content: str | None | utils.Undefined = MISSING, + embeds: list[Embed] | utils.Undefined = MISSING, + embed: Embed | None | utils.Undefined = MISSING, + file: File | utils.Undefined = MISSING, + files: list[File] | utils.Undefined = MISSING, + attachments: list[Attachment] | utils.Undefined = MISSING, + view: View | None | utils.Undefined = MISSING, allowed_mentions: AllowedMentions | None = None, - suppress: bool | None = MISSING, + suppress: bool | None | utils.Undefined = MISSING, ) -> WebhookMessage: """|coro| @@ -1473,8 +1473,8 @@ async def edit( self, *, reason: str | None = None, - name: str | None = MISSING, - avatar: bytes | None = MISSING, + name: str | None | utils.Undefined = MISSING, + avatar: bytes | None | utils.Undefined = MISSING, channel: Snowflake | None = None, prefer_auth: bool = True, ) -> Webhook: @@ -1588,22 +1588,22 @@ def _create_message(self, data): @overload async def send( self, - content: str = MISSING, + content: str | utils.Undefined = MISSING, *, - username: str = MISSING, + username: str | utils.Undefined = MISSING, avatar_url: Any = MISSING, - tts: bool = MISSING, - ephemeral: bool = MISSING, - file: File = MISSING, - files: list[File] = MISSING, - embed: Embed = MISSING, - embeds: list[Embed] = MISSING, - allowed_mentions: AllowedMentions = MISSING, - view: View = MISSING, - poll: Poll = MISSING, - thread: Snowflake = MISSING, + tts: bool | utils.Undefined = MISSING, + ephemeral: bool | utils.Undefined = MISSING, + file: File | utils.Undefined = MISSING, + files: list[File] | utils.Undefined = MISSING, + embed: Embed | utils.Undefined = MISSING, + embeds: list[Embed] | utils.Undefined = MISSING, + allowed_mentions: AllowedMentions | utils.Undefined = MISSING, + view: View | utils.Undefined = MISSING, + poll: Poll | utils.Undefined = MISSING, + thread: Snowflake | utils.Undefined = MISSING, thread_name: str | None = None, - applied_tags: list[Snowflake] = MISSING, + applied_tags: list[Snowflake] | utils.Undefined = MISSING, wait: Literal[True], delete_after: float = None, ) -> WebhookMessage: ... @@ -1611,44 +1611,44 @@ async def send( @overload async def send( self, - content: str = MISSING, + content: str | utils.Undefined = MISSING, *, - username: str = MISSING, + username: str | utils.Undefined = MISSING, avatar_url: Any = MISSING, - tts: bool = MISSING, - ephemeral: bool = MISSING, - file: File = MISSING, - files: list[File] = MISSING, - embed: Embed = MISSING, - embeds: list[Embed] = MISSING, - allowed_mentions: AllowedMentions = MISSING, - view: View = MISSING, - poll: Poll = MISSING, - thread: Snowflake = MISSING, - thread_name: str | None = None, - applied_tags: list[Snowflake] = MISSING, + tts: bool | utils.Undefined = MISSING, + ephemeral: bool | utils.Undefined = MISSING, + file: File | utils.Undefined = MISSING, + files: list[File] | utils.Undefined = MISSING, + embed: Embed | utils.Undefined = MISSING, + embeds: list[Embed] | utils.Undefined = MISSING, + allowed_mentions: AllowedMentions | utils.Undefined = MISSING, + view: View | utils.Undefined = MISSING, + poll: Poll | utils.Undefined = MISSING, + thread: Snowflake | utils.Undefined = MISSING, + thread_name: str | None | utils.Undefined = None, + applied_tags: list[Snowflake] | utils.Undefined = MISSING, wait: Literal[False] = ..., delete_after: float = None, ) -> None: ... async def send( self, - content: str = MISSING, + content: str | utils.Undefined = MISSING, *, - username: str = MISSING, - avatar_url: Any = MISSING, + username: str | utils.Undefined = MISSING, + avatar_url: Any | utils.Undefined = MISSING, tts: bool = False, ephemeral: bool = False, - file: File = MISSING, - files: list[File] = MISSING, - embed: Embed = MISSING, - embeds: list[Embed] = MISSING, - allowed_mentions: AllowedMentions = MISSING, - view: View = MISSING, - poll: Poll = MISSING, - thread: Snowflake = MISSING, + file: File | utils.Undefined = MISSING, + files: list[File] | utils.Undefined = MISSING, + embed: Embed | utils.Undefined = MISSING, + embeds: list[Embed] | utils.Undefined = MISSING, + allowed_mentions: AllowedMentions | utils.Undefined = MISSING, + view: View | utils.Undefined = MISSING, + poll: Poll | utils.Undefined = MISSING, + thread: Snowflake | utils.Undefined = MISSING, thread_name: str | None = None, - applied_tags: list[Snowflake] = MISSING, + applied_tags: list[Snowflake] | utils.Undefined = MISSING, wait: bool = False, delete_after: float = None, ) -> WebhookMessage | None: @@ -1905,15 +1905,15 @@ async def edit_message( self, message_id: int, *, - content: str | None = MISSING, - embeds: list[Embed] = MISSING, - embed: Embed | None = MISSING, - file: File = MISSING, - files: list[File] = MISSING, - attachments: list[Attachment] = MISSING, - view: View | None = MISSING, + content: str | None | utils.Undefined = MISSING, + embeds: list[Embed] | utils.Undefined = MISSING, + embed: Embed | None | utils.Undefined = MISSING, + file: File | utils.Undefined = MISSING, + files: list[File] | utils.Undefined = MISSING, + attachments: list[Attachment] | utils.Undefined = MISSING, + view: View | None | utils.Undefined = MISSING, allowed_mentions: AllowedMentions | None = None, - thread: Snowflake | None = MISSING, + thread: Snowflake | None | utils.Undefined = MISSING, suppress: bool = False, ) -> WebhookMessage: """|coro| diff --git a/discord/webhook/sync.py b/discord/webhook/sync.py index d2d3213d71..dcb26482ed 100644 --- a/discord/webhook/sync.py +++ b/discord/webhook/sync.py @@ -466,13 +466,13 @@ class SyncWebhookMessage(Message): def edit( self, - content: str | None = MISSING, - embeds: list[Embed] = MISSING, - embed: Embed | None = MISSING, - file: File = MISSING, - files: list[File] = MISSING, + content: str | None | utils.Undefined = MISSING, + embeds: list[Embed] | utils.Undefined = MISSING, + embed: Embed | None | utils.Undefined = MISSING, + file: File | utils.Undefined = MISSING, + files: list[File] | utils.Undefined = MISSING, allowed_mentions: AllowedMentions | None = None, - suppress: bool | None = MISSING, + suppress: bool | None | utils.Undefined = MISSING, ) -> SyncWebhookMessage: """Edits the message. @@ -648,7 +648,7 @@ def partial( id: int, token: str, *, - session: Session = MISSING, + session: Session | utils.Undefined = MISSING, bot_token: str | None = None, ) -> SyncWebhook: """Creates a partial :class:`Webhook`. @@ -689,7 +689,7 @@ def partial( @classmethod def from_url( - cls, url: str, *, session: Session = MISSING, bot_token: str | None = None + cls, url: str, *, session: Session | utils.Undefined = MISSING, bot_token: str | None = None ) -> SyncWebhook: """Creates a partial :class:`Webhook` from a webhook URL. @@ -824,8 +824,8 @@ def edit( self, *, reason: str | None = None, - name: str | None = MISSING, - avatar: bytes | None = MISSING, + name: str | None | utils.Undefined = MISSING, + avatar: bytes | None | utils.Undefined = MISSING, channel: Snowflake | None = None, prefer_auth: bool = True, ) -> SyncWebhook: @@ -927,17 +927,17 @@ def _create_message(self, data): @overload def send( self, - content: str = MISSING, + content: str | utils.Undefined = MISSING, *, - username: str = MISSING, - avatar_url: Any = MISSING, - tts: bool = MISSING, - file: File = MISSING, - files: list[File] = MISSING, - embed: Embed = MISSING, - embeds: list[Embed] = MISSING, - allowed_mentions: AllowedMentions = MISSING, - thread: Snowflake = MISSING, + username: str | utils.Undefined = MISSING, + avatar_url: Any | utils.Undefined = MISSING, + tts: bool | utils.Undefined = MISSING, + file: File | utils.Undefined = MISSING, + files: list[File] | utils.Undefined = MISSING, + embed: Embed | utils.Undefined = MISSING, + embeds: list[Embed] | utils.Undefined = MISSING, + allowed_mentions: AllowedMentions | utils.Undefined = MISSING, + thread: Snowflake | utils.Undefined = MISSING, thread_name: str | None = None, wait: Literal[True], ) -> SyncWebhookMessage: ... @@ -945,35 +945,35 @@ def send( @overload def send( self, - content: str = MISSING, + content: str | utils.Undefined = MISSING, *, - username: str = MISSING, - avatar_url: Any = MISSING, - tts: bool = MISSING, - file: File = MISSING, - files: list[File] = MISSING, - embed: Embed = MISSING, - embeds: list[Embed] = MISSING, - allowed_mentions: AllowedMentions = MISSING, - thread: Snowflake = MISSING, + username: str | utils.Undefined = MISSING, + avatar_url: Any | utils.Undefined = MISSING, + tts: bool | utils.Undefined = MISSING, + file: File | utils.Undefined = MISSING, + files: list[File] | utils.Undefined = MISSING, + embed: Embed | utils.Undefined = MISSING, + embeds: list[Embed] | utils.Undefined = MISSING, + allowed_mentions: AllowedMentions | utils.Undefined = MISSING, + thread: Snowflake | utils.Undefined = MISSING, thread_name: str | None = None, wait: Literal[False] = ..., - suppress: bool = MISSING, + suppress: bool | utils.Undefined = MISSING, ) -> None: ... def send( self, - content: str = MISSING, + content: str | utils.Undefined = MISSING, *, - username: str = MISSING, - avatar_url: Any = MISSING, + username: str | utils.Undefined = MISSING, + avatar_url: Any | utils.Undefined = MISSING, tts: bool = False, - file: File = MISSING, - files: list[File] = MISSING, - embed: Embed = MISSING, - embeds: list[Embed] = MISSING, - allowed_mentions: AllowedMentions = MISSING, - thread: Snowflake = MISSING, + file: File | utils.Undefined = MISSING, + files: list[File] | utils.Undefined = MISSING, + embed: Embed | utils.Undefined = MISSING, + embeds: list[Embed] | utils.Undefined = MISSING, + allowed_mentions: AllowedMentions | utils.Undefined = MISSING, + thread: Snowflake | utils.Undefined = MISSING, thread_name: str | None = None, wait: bool = False, suppress: bool = False, @@ -1154,13 +1154,13 @@ def edit_message( self, message_id: int, *, - content: str | None = MISSING, - embeds: list[Embed] = MISSING, - embed: Embed | None = MISSING, - file: File = MISSING, - files: list[File] = MISSING, + content: str | None | utils.Undefined = MISSING, + embeds: list[Embed] | utils.Undefined = MISSING, + embed: Embed | None | utils.Undefined = MISSING, + file: File | utils.Undefined = MISSING, + files: list[File] | utils.Undefined = MISSING, allowed_mentions: AllowedMentions | None = None, - thread: Snowflake | None = MISSING, + thread: Snowflake | None | utils.Undefined = MISSING, suppress: bool = False, ) -> SyncWebhookMessage: """Edits a message owned by this webhook.