Skip to content

Commit 61cc544

Browse files
yoggyspre-commit-ci[bot]plun1331NeloBlivionDorukyum
authored
fix: overall type-hinting improvements (#2457)
* fix: RawMemberRemoveEvent type-hinting * Update CHANGELOG.md Signed-off-by: YoggieS <[email protected]> * style(pre-commit): auto fixes from pre-commit.com hooks * Update CHANGELOG.md Co-authored-by: plun1331 <[email protected]> Signed-off-by: YoggieS <[email protected]> * fix: overall type-hinting * style(pre-commit): auto fixes from pre-commit.com hooks * fix: further types lookup & fixes * style(pre-commit): auto fixes from pre-commit.com hooks * Update discord/guild.py Co-authored-by: UK <[email protected]> Signed-off-by: YoggieS <[email protected]> * review suggestions * review suggestions v2 * style(pre-commit): auto fixes from pre-commit.com hooks * review suggestions v3 * update changelog with correct # * nonce typing partial revert * onboarding PromptOption types * Update CHANGELOG.md Co-authored-by: Dorukyum <[email protected]> Signed-off-by: YoggieS <[email protected]> --------- Signed-off-by: YoggieS <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: plun1331 <[email protected]> Co-authored-by: UK <[email protected]> Co-authored-by: Dorukyum <[email protected]>
1 parent 9fc3d7b commit 61cc544

27 files changed

+98
-73
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ These changes are available on the `master` branch, but have not yet been releas
5252
([#2448](https://github.com/Pycord-Development/pycord/pull/2448))
5353
- Fixed missing `application_id` in `Entitlement.delete`.
5454
([#2458](https://github.com/Pycord-Development/pycord/pull/2458))
55+
- Fixed many inaccurate type hints throughout the library.
56+
([#2457](https://github.com/Pycord-Development/pycord/pull/2457))
5557

5658
### Changed
5759

discord/abc.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ async def _single_delete_strategy(
115115

116116

117117
async def _purge_messages_helper(
118-
channel: TextChannel | Thread | VoiceChannel,
118+
channel: TextChannel | StageChannel | Thread | VoiceChannel,
119119
*,
120120
limit: int | None = 100,
121121
check: Callable[[Message], bool] = MISSING,
@@ -1345,7 +1345,7 @@ async def send(
13451345
file: File = ...,
13461346
stickers: Sequence[GuildSticker | StickerItem] = ...,
13471347
delete_after: float = ...,
1348-
nonce: str | int = ...,
1348+
nonce: int | str = ...,
13491349
enforce_nonce: bool = ...,
13501350
allowed_mentions: AllowedMentions = ...,
13511351
reference: Message | MessageReference | PartialMessage = ...,
@@ -1365,7 +1365,7 @@ async def send(
13651365
files: list[File] = ...,
13661366
stickers: Sequence[GuildSticker | StickerItem] = ...,
13671367
delete_after: float = ...,
1368-
nonce: str | int = ...,
1368+
nonce: int | str = ...,
13691369
enforce_nonce: bool = ...,
13701370
allowed_mentions: AllowedMentions = ...,
13711371
reference: Message | MessageReference | PartialMessage = ...,
@@ -1385,7 +1385,7 @@ async def send(
13851385
file: File = ...,
13861386
stickers: Sequence[GuildSticker | StickerItem] = ...,
13871387
delete_after: float = ...,
1388-
nonce: str | int = ...,
1388+
nonce: int | str = ...,
13891389
enforce_nonce: bool = ...,
13901390
allowed_mentions: AllowedMentions = ...,
13911391
reference: Message | MessageReference | PartialMessage = ...,
@@ -1405,7 +1405,7 @@ async def send(
14051405
files: list[File] = ...,
14061406
stickers: Sequence[GuildSticker | StickerItem] = ...,
14071407
delete_after: float = ...,
1408-
nonce: str | int = ...,
1408+
nonce: int | str = ...,
14091409
enforce_nonce: bool = ...,
14101410
allowed_mentions: AllowedMentions = ...,
14111411
reference: Message | MessageReference | PartialMessage = ...,
@@ -1465,7 +1465,7 @@ async def send(
14651465
The file to upload.
14661466
files: List[:class:`~discord.File`]
14671467
A list of files to upload. Must be a maximum of 10.
1468-
nonce: :class:`int`
1468+
nonce: Union[:class:`str`, :class:`int`]
14691469
The nonce to use for sending this message. If the message was successfully sent,
14701470
then the message will have a nonce with this value.
14711471
enforce_nonce: Optional[:class:`bool`]

discord/audit_logs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,16 @@ def _transform_type(
193193

194194
def _transform_actions(
195195
entry: AuditLogEntry, data: list[AutoModActionPayload] | None
196-
) -> AutoModAction | None:
196+
) -> list[AutoModAction] | None:
197197
if data is None:
198198
return None
199199
else:
200200
return [AutoModAction.from_dict(d) for d in data]
201201

202202

203203
def _transform_trigger_metadata(
204-
entry: AuditLogEntry, data: list[AutoModActionPayload] | None
205-
) -> AutoModAction | None:
204+
entry: AuditLogEntry, data: AutoModTriggerMetadataPayload | None
205+
) -> AutoModTriggerMetadata | None:
206206
if data is None:
207207
return None
208208
else:
@@ -309,7 +309,7 @@ def __init__(
309309
"$add_allow_list",
310310
]:
311311
self._handle_trigger_metadata(
312-
self.before, self.after, entry, elem["new_value"], attr
312+
self.before, self.after, entry, elem["new_value"], attr # type: ignore
313313
)
314314
continue
315315
elif attr in [
@@ -318,7 +318,7 @@ def __init__(
318318
"$remove_allow_list",
319319
]:
320320
self._handle_trigger_metadata(
321-
self.after, self.before, entry, elem["new_value"], attr
321+
self.after, self.before, entry, elem["new_value"], attr # type: ignore
322322
)
323323
continue
324324

discord/channel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ async def create_thread(
12181218
A list of stickers to upload. Must be a maximum of 3.
12191219
delete_message_after: :class:`int`
12201220
The time to wait before deleting the thread.
1221-
nonce: :class:`int`
1221+
nonce: Union[:class:`str`, :class:`int`]
12221222
The nonce to use for sending this message. If the message was successfully sent,
12231223
then the message will have a nonce with this value.
12241224
allowed_mentions: :class:`~discord.AllowedMentions`

discord/commands/context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import discord
3838
from .. import Bot
3939
from ..state import ConnectionState
40-
from ..voice_client import VoiceProtocol
40+
from ..voice_client import VoiceClient
4141

4242
from .core import ApplicationCommand, Option
4343
from ..interactions import InteractionChannel
@@ -211,7 +211,7 @@ def user(self) -> Member | User:
211211
author: Member | User = user
212212

213213
@property
214-
def voice_client(self) -> VoiceProtocol | None:
214+
def voice_client(self) -> VoiceClient | None:
215215
"""Returns the voice client associated with this context's command.
216216
Shorthand for :attr:`Interaction.guild.voice_client<~discord.Guild.voice_client>`, if applicable.
217217
"""

discord/commands/core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def is_on_cooldown(self, ctx: ApplicationContext) -> bool:
328328
if not self._buckets.valid:
329329
return False
330330

331-
bucket = self._buckets.get_bucket(ctx)
331+
bucket = self._buckets.get_bucket(ctx) # type: ignore
332332
current = utcnow().timestamp()
333333
return bucket.get_tokens(current) == 0
334334

@@ -363,7 +363,7 @@ def get_cooldown_retry_after(self, ctx: ApplicationContext) -> float:
363363
If this is ``0.0`` then the command isn't on cooldown.
364364
"""
365365
if self._buckets.valid:
366-
bucket = self._buckets.get_bucket(ctx)
366+
bucket = self._buckets.get_bucket(ctx) # type: ignore
367367
current = utcnow().timestamp()
368368
return bucket.get_retry_after(current)
369369

@@ -1245,7 +1245,7 @@ def to_dict(self) -> dict:
12451245

12461246
return as_dict
12471247

1248-
def add_command(self, command: SlashCommand) -> None:
1248+
def add_command(self, command: SlashCommand | SlashCommandGroup) -> None:
12491249
if command.cog is None and self.cog is not None:
12501250
command.cog = self.cog
12511251

discord/context_managers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
__all__ = ("Typing",)
3939

4040

41-
def _typing_done_callback(fut: asyncio.Future) -> None:
41+
def _typing_done_callback(fut: asyncio.Task) -> None:
4242
# just retrieve any exception and call it a day
4343
try:
4444
fut.exception()

discord/ext/commands/converter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ async def _actual_conversion(
11661166

11671167

11681168
async def run_converters(
1169-
ctx: Context, converter, argument: str, param: inspect.Parameter
1169+
ctx: Context, converter, argument: str | None, param: inspect.Parameter
11701170
):
11711171
"""|coro|
11721172
@@ -1182,7 +1182,7 @@ async def run_converters(
11821182
The invocation context to run the converters under.
11831183
converter: Any
11841184
The converter to run, this corresponds to the annotation in the function.
1185-
argument: :class:`str`
1185+
argument: Optional[:class:`str`]
11861186
The argument to convert to.
11871187
param: :class:`inspect.Parameter`
11881188
The parameter being converted. This is mainly for error reporting.

discord/ext/commands/help.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,13 @@ class Paginator:
9090
.. versionadded:: 1.7
9191
"""
9292

93-
def __init__(self, prefix="```", suffix="```", max_size=2000, linesep="\n"):
93+
def __init__(
94+
self,
95+
prefix: str | None = "```",
96+
suffix: str | None = "```",
97+
max_size: int = 2000,
98+
linesep: str = "\n",
99+
):
94100
self.prefix = prefix
95101
self.suffix = suffix
96102
self.max_size = max_size

discord/guild.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
from .types.member import Member as MemberPayload
108108
from .types.threads import Thread as ThreadPayload
109109
from .types.voice import GuildVoiceState
110-
from .voice_client import VoiceProtocol
110+
from .voice_client import VoiceClient
111111
from .webhook import Webhook
112112

113113
VocalGuildChannel = Union[VoiceChannel, StageChannel]
@@ -647,8 +647,8 @@ def me(self) -> Member:
647647
return self.get_member(self_id) # type: ignore
648648

649649
@property
650-
def voice_client(self) -> VoiceProtocol | None:
651-
"""Returns the :class:`VoiceProtocol` associated with this guild, if any."""
650+
def voice_client(self) -> VoiceClient | None:
651+
"""Returns the :class:`VoiceClient` associated with this guild, if any."""
652652
return self._state._get_voice_client(self.id)
653653

654654
@property
@@ -3121,7 +3121,7 @@ async def bulk_ban(
31213121
*users: Snowflake,
31223122
delete_message_seconds: int | None = None,
31233123
reason: str | None = None,
3124-
) -> list[list[Snowflake], list[Snowflake]]:
3124+
) -> tuple[list[Snowflake], list[Snowflake]]:
31253125
r"""|coro|
31263126
31273127
Bulk ban users from the guild.
@@ -3152,7 +3152,7 @@ async def bulk_ban(
31523152
31533153
Returns
31543154
-------
3155-
List[List[:class:`abc.Snowflake`], List[:class:`abc.Snowflake`]]
3155+
Tuple[List[:class:`abc.Snowflake`], List[:class:`abc.Snowflake`]]
31563156
Returns two lists: the first contains members that were successfully banned, while the second is members that could not be banned.
31573157
31583158
Raises

discord/http.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ def send_message(
464464
tts: bool = False,
465465
embed: embed.Embed | None = None,
466466
embeds: list[embed.Embed] | None = None,
467-
nonce: str | None = None,
467+
nonce: int | str | None = None,
468468
enforce_nonce: bool | None = None,
469469
allowed_mentions: message.AllowedMentions | None = None,
470470
message_reference: message.MessageReference | None = None,
@@ -524,7 +524,7 @@ def send_multipart_helper(
524524
tts: bool = False,
525525
embed: embed.Embed | None = None,
526526
embeds: Iterable[embed.Embed | None] | None = None,
527-
nonce: str | None = None,
527+
nonce: int | str | None = None,
528528
enforce_nonce: bool | None = None,
529529
allowed_mentions: message.AllowedMentions | None = None,
530530
message_reference: message.MessageReference | None = None,
@@ -587,7 +587,7 @@ def send_files(
587587
tts: bool = False,
588588
embed: embed.Embed | None = None,
589589
embeds: list[embed.Embed] | None = None,
590-
nonce: str | None = None,
590+
nonce: int | str | None = None,
591591
enforce_nonce: bool | None = None,
592592
allowed_mentions: message.AllowedMentions | None = None,
593593
message_reference: message.MessageReference | None = None,
@@ -1203,7 +1203,7 @@ def start_forum_thread(
12031203
files: Sequence[File] | None = None,
12041204
embed: embed.Embed | None = None,
12051205
embeds: list[embed.Embed] | None = None,
1206-
nonce: str | None = None,
1206+
nonce: int | str | None = None,
12071207
allowed_mentions: message.AllowedMentions | None = None,
12081208
stickers: list[sticker.StickerItem] | None = None,
12091209
components: list[components.Component] | None = None,
@@ -2151,8 +2151,8 @@ def edit_channel_permissions(
21512151
self,
21522152
channel_id: Snowflake,
21532153
target: Snowflake,
2154-
allow: str,
2155-
deny: str,
2154+
allow: int | str,
2155+
deny: int | str,
21562156
type: channel.OverwriteType,
21572157
*,
21582158
reason: str | None = None,

discord/interactions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ async def premium_required(self) -> Interaction:
12211221
self._responded = True
12221222
return self._parent
12231223

1224-
async def _locked_response(self, coro: Coroutine[Any]):
1224+
async def _locked_response(self, coro: Coroutine[Any, Any, Any]) -> None:
12251225
"""|coro|
12261226
12271227
Wraps a response and makes sure that it's locked while executing.

discord/invite.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
from .types.invite import GatewayInvite as GatewayInvitePayload
5050
from .types.invite import Invite as InvitePayload
5151
from .types.invite import InviteGuild as InviteGuildPayload
52+
from .types.invite import VanityInvite as VanityInvitePayload
5253
from .types.scheduled_events import ScheduledEvent as ScheduledEventPayload
5354
from .user import User
5455

@@ -353,7 +354,7 @@ def __init__(
353354
self,
354355
*,
355356
state: ConnectionState,
356-
data: InvitePayload,
357+
data: InvitePayload | VanityInvitePayload,
357358
guild: PartialInviteGuild | Guild | None = None,
358359
channel: PartialInviteChannel | GuildChannel | None = None,
359360
):

discord/member.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
from .types.member import MemberWithUser as MemberWithUserPayload
6363
from .types.member import UserWithMember as UserWithMemberPayload
6464
from .types.user import User as UserPayload
65+
from .types.voice import GuildVoiceState as GuildVoiceStatePayload
6566
from .types.voice import VoiceState as VoiceStatePayload
6667

6768
VocalGuildChannel = Union[VoiceChannel, StageChannel]
@@ -125,12 +126,19 @@ class VoiceState:
125126
)
126127

127128
def __init__(
128-
self, *, data: VoiceStatePayload, channel: VocalGuildChannel | None = None
129+
self,
130+
*,
131+
data: VoiceStatePayload | GuildVoiceStatePayload,
132+
channel: VocalGuildChannel | None = None,
129133
):
130134
self.session_id: str = data.get("session_id")
131135
self._update(data, channel)
132136

133-
def _update(self, data: VoiceStatePayload, channel: VocalGuildChannel | None):
137+
def _update(
138+
self,
139+
data: VoiceStatePayload | GuildVoiceStatePayload,
140+
channel: VocalGuildChannel | None,
141+
):
134142
self.self_mute: bool = data.get("self_mute", False)
135143
self.self_deaf: bool = data.get("self_deaf", False)
136144
self.self_stream: bool = data.get("self_stream", False)

discord/message.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,14 @@ def __init__(self, *, data: AttachmentPayload, state: ConnectionState):
240240
setattr(self, attr, value)
241241

242242
@property
243-
def expires_at(self) -> datetime.datetime:
243+
def expires_at(self) -> datetime.datetime | None:
244244
"""This attachment URL's expiry time in UTC."""
245245
if not self._ex:
246246
return None
247247
return datetime.datetime.utcfromtimestamp(int(self._ex, 16))
248248

249249
@property
250-
def issued_at(self) -> datetime.datetime:
250+
def issued_at(self) -> datetime.datetime | None:
251251
"""The attachment URL's issue time in UTC."""
252252
if not self._is:
253253
return None

discord/partial_emoji.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ class PartialEmoji(_EmojiTag, AssetMixin):
100100
if TYPE_CHECKING:
101101
id: int | None
102102

103-
def __init__(self, *, name: str, animated: bool = False, id: int | None = None):
103+
def __init__(
104+
self, *, name: str | None, animated: bool = False, id: int | None = None
105+
):
104106
self.animated = animated
105107
self.name = name
106108
self.id = id

discord/raw_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
from .automod import AutoModAction, AutoModTriggerType
3232
from .enums import AuditLogAction, ChannelType, ReactionType, try_enum
33-
from .types.user import User
3433

3534
if TYPE_CHECKING:
3635
from .abc import MessageableChannel
@@ -58,6 +57,7 @@
5857
TypingEvent,
5958
VoiceChannelStatusUpdateEvent,
6059
)
60+
from .user import User
6161

6262

6363
__all__ = (

discord/reaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def __init__(
111111
self.me: bool = data.get("me")
112112
self.burst: bool = data.get("burst")
113113
self.me_burst: bool = data.get("me_burst")
114-
self._burst_colours: list[Colour] = data.get("burst_colors", [])
114+
self._burst_colours: list[str] = data.get("burst_colors", [])
115115

116116
@property
117117
def burst_colours(self) -> list[Colour]:

0 commit comments

Comments
 (0)