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

0 commit comments

Comments
 (0)