Skip to content

Commit de83d48

Browse files
authored
refactor!: properly type MISSING (#2)
* refactor!: properly type MISSING * chore: MISSING does not need to be Any * fix: comparisons * fix: wtf is a _MISSING
1 parent f3243bf commit de83d48

35 files changed

+401
-405
lines changed

discord/abc.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ async def _purge_messages_helper(
118118
channel: TextChannel | StageChannel | Thread | VoiceChannel,
119119
*,
120120
limit: int | None = 100,
121-
check: Callable[[Message], bool] = MISSING,
121+
check: Callable[[Message], bool] | utils.Undefined = MISSING,
122122
before: SnowflakeTime | None = None,
123123
after: SnowflakeTime | None = None,
124124
around: SnowflakeTime | None = None,
@@ -1031,43 +1031,43 @@ async def move(
10311031
self,
10321032
*,
10331033
beginning: bool,
1034-
offset: int = MISSING,
1035-
category: Snowflake | None = MISSING,
1036-
sync_permissions: bool = MISSING,
1037-
reason: str | None = MISSING,
1034+
offset: int | utils.Undefined = MISSING,
1035+
category: Snowflake | None | utils.Undefined = MISSING,
1036+
sync_permissions: bool | utils.Undefined = MISSING,
1037+
reason: str | None | utils.Undefined = MISSING,
10381038
) -> None: ...
10391039

10401040
@overload
10411041
async def move(
10421042
self,
10431043
*,
10441044
end: bool,
1045-
offset: int = MISSING,
1046-
category: Snowflake | None = MISSING,
1047-
sync_permissions: bool = MISSING,
1048-
reason: str = MISSING,
1045+
offset: int | utils.Undefined = MISSING,
1046+
category: Snowflake | None | utils.Undefined = MISSING,
1047+
sync_permissions: bool | utils.Undefined = MISSING,
1048+
reason: str | utils.Undefined = MISSING,
10491049
) -> None: ...
10501050

10511051
@overload
10521052
async def move(
10531053
self,
10541054
*,
10551055
before: Snowflake,
1056-
offset: int = MISSING,
1057-
category: Snowflake | None = MISSING,
1058-
sync_permissions: bool = MISSING,
1059-
reason: str = MISSING,
1056+
offset: int | utils.Undefined = MISSING,
1057+
category: Snowflake | None | utils.Undefined = MISSING,
1058+
sync_permissions: bool | utils.Undefined = MISSING,
1059+
reason: str | utils.Undefined = MISSING,
10601060
) -> None: ...
10611061

10621062
@overload
10631063
async def move(
10641064
self,
10651065
*,
10661066
after: Snowflake,
1067-
offset: int = MISSING,
1068-
category: Snowflake | None = MISSING,
1069-
sync_permissions: bool = MISSING,
1070-
reason: str = MISSING,
1067+
offset: int | utils.Undefined = MISSING,
1068+
category: Snowflake | None | utils.Undefined = MISSING,
1069+
sync_permissions: bool | utils.Undefined = MISSING,
1070+
reason: str | utils.Undefined = MISSING,
10711071
) -> None: ...
10721072

10731073
async def move(self, **kwargs) -> None:

discord/application_role_connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from typing import TYPE_CHECKING
2828

2929
from .enums import ApplicationRoleConnectionMetadataType, try_enum
30-
from .utils import MISSING
30+
from .utils import MISSING, Undefined
3131

3232
if TYPE_CHECKING:
3333
from .types.application_role_connection import (
@@ -77,8 +77,8 @@ def __init__(
7777
key: str,
7878
name: str,
7979
description: str,
80-
name_localizations: dict[str, str] = MISSING,
81-
description_localizations: dict[str, str] = MISSING,
80+
name_localizations: dict[str, str] | Undefined = MISSING,
81+
description_localizations: dict[str, str] | Undefined = MISSING,
8282
):
8383
self.type: ApplicationRoleConnectionMetadataType = type
8484
self.key: str = key

discord/asset.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@ def is_animated(self) -> bool:
333333
def replace(
334334
self,
335335
*,
336-
size: int = MISSING,
337-
format: ValidAssetFormatTypes = MISSING,
338-
static_format: ValidStaticFormatTypes = MISSING,
336+
size: int | utils.Undefined = MISSING,
337+
format: ValidAssetFormatTypes | utils.Undefined = MISSING,
338+
static_format: ValidStaticFormatTypes | utils.Undefined = MISSING,
339339
) -> Asset:
340340
"""Returns a new asset with the passed components replaced.
341341

discord/automod.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ class AutoModActionMetadata:
9292

9393
def __init__(
9494
self,
95-
channel_id: int = MISSING,
96-
timeout_duration: timedelta = MISSING,
97-
custom_message: str = MISSING,
95+
channel_id: int | utils.Undefined = MISSING,
96+
timeout_duration: timedelta | utils.Undefined = MISSING,
97+
custom_message: str | utils.Undefined = MISSING,
9898
):
9999
self.channel_id: int = channel_id
100100
self.timeout_duration: timedelta = timeout_duration
@@ -247,11 +247,11 @@ class AutoModTriggerMetadata:
247247

248248
def __init__(
249249
self,
250-
keyword_filter: list[str] = MISSING,
251-
regex_patterns: list[str] = MISSING,
252-
presets: list[AutoModKeywordPresetType] = MISSING,
253-
allow_list: list[str] = MISSING,
254-
mention_total_limit: int = MISSING,
250+
keyword_filter: list[str] | utils.Undefined = MISSING,
251+
regex_patterns: list[str] | utils.Undefined = MISSING,
252+
presets: list[AutoModKeywordPresetType] | utils.Undefined = MISSING,
253+
allow_list: list[str] | utils.Undefined = MISSING,
254+
mention_total_limit: int | utils.Undefined = MISSING,
255255
):
256256
self.keyword_filter = keyword_filter
257257
self.regex_patterns = regex_patterns
@@ -483,13 +483,13 @@ async def delete(self, reason: str | None = None) -> None:
483483
async def edit(
484484
self,
485485
*,
486-
name: str = MISSING,
487-
event_type: AutoModEventType = MISSING,
488-
trigger_metadata: AutoModTriggerMetadata = MISSING,
489-
actions: list[AutoModAction] = MISSING,
490-
enabled: bool = MISSING,
491-
exempt_roles: list[Snowflake] = MISSING,
492-
exempt_channels: list[Snowflake] = MISSING,
486+
name: str | utils.Undefined = MISSING,
487+
event_type: AutoModEventType | utils.Undefined = MISSING,
488+
trigger_metadata: AutoModTriggerMetadata | utils.Undefined = MISSING,
489+
actions: list[AutoModAction] | utils.Undefined = MISSING,
490+
enabled: bool | utils.Undefined = MISSING,
491+
exempt_roles: list[Snowflake] | utils.Undefined = MISSING,
492+
exempt_channels: list[Snowflake] | utils.Undefined = MISSING,
493493
reason: str | None = None,
494494
) -> AutoModRule | None:
495495
"""|coro|

discord/channel.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ async def purge(
389389
self,
390390
*,
391391
limit: int | None = 100,
392-
check: Callable[[Message], bool] = MISSING,
392+
check: Callable[[Message], bool] | utils.Undefined = MISSING,
393393
before: SnowflakeTime | None = None,
394394
after: SnowflakeTime | None = None,
395395
around: SnowflakeTime | None = None,
@@ -864,7 +864,7 @@ async def create_thread(
864864
*,
865865
name: str,
866866
message: Snowflake | None = None,
867-
auto_archive_duration: ThreadArchiveDuration = MISSING,
867+
auto_archive_duration: ThreadArchiveDuration | utils.Undefined = MISSING,
868868
type: ChannelType | None = None,
869869
slowmode_delay: int | None = None,
870870
invitable: bool | None = None,
@@ -1193,8 +1193,8 @@ async def create_thread(
11931193
allowed_mentions=None,
11941194
view=None,
11951195
applied_tags=None,
1196-
auto_archive_duration: ThreadArchiveDuration = MISSING,
1197-
slowmode_delay: int = MISSING,
1196+
auto_archive_duration: ThreadArchiveDuration | utils.Undefined = MISSING,
1197+
slowmode_delay: int | utils.Undefined = MISSING,
11981198
reason: str | None = None,
11991199
) -> Thread:
12001200
"""|coro|
@@ -1868,7 +1868,7 @@ async def purge(
18681868
self,
18691869
*,
18701870
limit: int | None = 100,
1871-
check: Callable[[Message], bool] = MISSING,
1871+
check: Callable[[Message], bool] | utils.Undefined = MISSING,
18721872
before: SnowflakeTime | None = None,
18731873
after: SnowflakeTime | None = None,
18741874
around: SnowflakeTime | None = None,
@@ -2418,7 +2418,7 @@ async def purge(
24182418
self,
24192419
*,
24202420
limit: int | None = 100,
2421-
check: Callable[[Message], bool] = MISSING,
2421+
check: Callable[[Message], bool] | utils.Undefined = MISSING,
24222422
before: SnowflakeTime | None = None,
24232423
after: SnowflakeTime | None = None,
24242424
around: SnowflakeTime | None = None,
@@ -2599,7 +2599,7 @@ async def create_instance(
25992599
self,
26002600
*,
26012601
topic: str,
2602-
privacy_level: StagePrivacyLevel = MISSING,
2602+
privacy_level: StagePrivacyLevel | utils.Undefined = MISSING,
26032603
reason: str | None = None,
26042604
send_notification: bool | None = False,
26052605
) -> StageInstance:

discord/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ def _check(*args):
12461246
return asyncio.wait_for(future, timeout)
12471247

12481248
# event registration
1249-
def add_listener(self, func: Coro, name: str = MISSING) -> None:
1249+
def add_listener(self, func: Coro, name: str | utils.Undefined = MISSING) -> None:
12501250
"""The non decorator alternative to :meth:`.listen`.
12511251
12521252
Parameters
@@ -1293,7 +1293,7 @@ async def my_message(message): pass
12931293
name,
12941294
)
12951295

1296-
def remove_listener(self, func: Coro, name: str = MISSING) -> None:
1296+
def remove_listener(self, func: Coro, name: str | utils.Undefined = MISSING) -> None:
12971297
"""Removes a listener from the pool of listeners.
12981298
12991299
Parameters
@@ -1313,7 +1313,7 @@ def remove_listener(self, func: Coro, name: str = MISSING) -> None:
13131313
except ValueError:
13141314
pass
13151315

1316-
def listen(self, name: str = MISSING, once: bool = False) -> Callable[[Coro], Coro]:
1316+
def listen(self, name: str | utils.Undefined = MISSING, once: bool = False) -> Callable[[Coro], Coro]:
13171317
"""A decorator that registers another function as an external
13181318
event listener. Basically this allows you to listen to multiple
13191319
events from different places e.g. such as :func:`.on_ready`
@@ -1597,8 +1597,8 @@ async def create_guild(
15971597
self,
15981598
*,
15991599
name: str,
1600-
icon: bytes = MISSING,
1601-
code: str = MISSING,
1600+
icon: bytes | utils.Undefined = MISSING,
1601+
code: str | utils.Undefined = MISSING,
16021602
) -> Guild:
16031603
"""|coro|
16041604

discord/cog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def _get_overridden_method(cls, method: FuncT) -> FuncT | None:
369369

370370
@classmethod
371371
def listener(
372-
cls, name: str = MISSING, once: bool = False
372+
cls, name: str | discord.utils.Undefined = MISSING, once: bool = False
373373
) -> Callable[[FuncT], FuncT]:
374374
"""A decorator that marks a function as a listener.
375375

discord/commands/options.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
from ..enums import ChannelType
4545
from ..enums import Enum as DiscordEnum
4646
from ..enums import SlashCommandOptionType
47-
from ..utils import MISSING, basic_autocomplete
47+
from ..utils import MISSING, Undefined, basic_autocomplete
4848

4949
if TYPE_CHECKING:
5050
from ..ext.commands import Converter
@@ -414,7 +414,7 @@ def __init__(
414414
self,
415415
name: str,
416416
value: str | int | float | None = None,
417-
name_localizations: dict[str, str] = MISSING,
417+
name_localizations: dict[str, str] | Undefined = MISSING,
418418
):
419419
self.name = str(name)
420420
self.value = value if value is not None else name

discord/components.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
from .enums import ButtonStyle, ChannelType, ComponentType, InputTextStyle, try_enum
3131
from .partial_emoji import PartialEmoji, _EmojiTag
32-
from .utils import MISSING, get_slots
32+
from .utils import MISSING, Undefined, get_slots
3333

3434
if TYPE_CHECKING:
3535
from .emoji import AppEmoji, GuildEmoji
@@ -410,7 +410,7 @@ def __init__(
410410
self,
411411
*,
412412
label: str,
413-
value: str = MISSING,
413+
value: str | Undefined = MISSING,
414414
description: str | None = None,
415415
emoji: str | GuildEmoji | AppEmoji | PartialEmoji | None = None,
416416
default: bool = False,

discord/emoji.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from .asset import Asset, AssetMixin
3131
from .partial_emoji import PartialEmoji, _EmojiTag
3232
from .user import User
33-
from .utils import MISSING, SnowflakeList, snowflake_time
33+
from .utils import MISSING, SnowflakeList, Undefined, snowflake_time
3434

3535
__all__ = (
3636
"Emoji",
@@ -234,8 +234,8 @@ async def delete(self, *, reason: str | None = None) -> None:
234234
async def edit(
235235
self,
236236
*,
237-
name: str = MISSING,
238-
roles: list[Snowflake] = MISSING,
237+
name: str | Undefined = MISSING,
238+
roles: list[Snowflake] | Undefined = MISSING,
239239
reason: str | None = None,
240240
) -> GuildEmoji:
241241
r"""|coro|
@@ -383,7 +383,7 @@ async def delete(self) -> None:
383383
async def edit(
384384
self,
385385
*,
386-
name: str = MISSING,
386+
name: str | Undefined = MISSING,
387387
) -> AppEmoji:
388388
r"""|coro|
389389

0 commit comments

Comments
 (0)