Skip to content

Commit fbe467c

Browse files
committed
fix: remove unnecessary type ignores for context in cooldown handling + correct typehint of max_concurrency since only ctx is passed and never message
1 parent e8356e7 commit fbe467c

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

discord/commands/core.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def guild_only(self, value: bool) -> None:
336336
async def _prepare_cooldowns(self, ctx: ApplicationContext):
337337
if self._buckets.valid:
338338
current = datetime.datetime.now().timestamp()
339-
bucket = await self._buckets.get_bucket(ctx, current) # type: ignore # ctx instead of non-existent message
339+
bucket = await self._buckets.get_bucket(ctx, current)
340340

341341
if bucket is not None:
342342
retry_after = bucket.update_rate_limit(current)
@@ -356,9 +356,7 @@ async def prepare(self, ctx: ApplicationContext) -> None:
356356
)
357357

358358
if self._max_concurrency is not None:
359-
# For this application, context can be duck-typed as a Message
360-
await self._max_concurrency.acquire(ctx) # type: ignore # ctx instead of non-existent message
361-
359+
await self._max_concurrency.acquire(ctx)
362360
try:
363361
await self._prepare_cooldowns(ctx)
364362
await self.call_before_hooks(ctx)
@@ -400,7 +398,7 @@ def reset_cooldown(self, ctx: ApplicationContext) -> None:
400398
The invocation context to reset the cooldown under.
401399
"""
402400
if self._buckets.valid:
403-
bucket = self._buckets.get_bucket(ctx) # type: ignore # ctx instead of non-existent message
401+
bucket = self._buckets.get_bucket(ctx)
404402
bucket.reset()
405403

406404
def get_cooldown_retry_after(self, ctx: ApplicationContext) -> float:

discord/ext/commands/cooldowns.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,11 @@ def __repr__(self) -> str:
399399
f"<MaxConcurrency per={self.per!r} number={self.number} wait={self.wait}>"
400400
)
401401

402-
def get_key(self, message: Message) -> Any:
403-
return self.per.get_key(message)
402+
def get_key(self, ctx: Context | ApplicationContext) -> Any:
403+
return self.per.get_key(ctx)
404404

405-
async def acquire(self, message: Message) -> None:
406-
key = self.get_key(message)
405+
async def acquire(self, ctx: Context | ApplicationContext) -> None:
406+
key = self.get_key(ctx)
407407

408408
try:
409409
sem = self._mapping[key]
@@ -414,10 +414,10 @@ async def acquire(self, message: Message) -> None:
414414
if not acquired:
415415
raise MaxConcurrencyReached(self.number, self.per)
416416

417-
async def release(self, message: Message) -> None:
417+
async def release(self, ctx: Context | ApplicationContext) -> None:
418418
# Technically there's no reason for this function to be async
419419
# But it might be more useful in the future
420-
key = self.get_key(message)
420+
key = self.get_key(ctx)
421421

422422
try:
423423
sem = self._mapping[key]

discord/ext/commands/core.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -873,8 +873,7 @@ async def prepare(self, ctx: Context) -> None:
873873
)
874874

875875
if self._max_concurrency is not None:
876-
# For this application, context can be duck-typed as a Message
877-
await self._max_concurrency.acquire(ctx) # type: ignore
876+
await self._max_concurrency.acquire(ctx)
878877

879878
try:
880879
if self.cooldown_after_parsing:

0 commit comments

Comments
 (0)