Skip to content

Commit 8c035cb

Browse files
committed
replace asyncio.iscoroutinefunction refs (deprecated) with inspect.iscoroutinefunction
1 parent 7d21354 commit 8c035cb

File tree

5 files changed

+18
-16
lines changed

5 files changed

+18
-16
lines changed

discord/bot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,7 @@ def before_invoke(self, coro):
13861386
TypeError
13871387
The coroutine passed is not actually a coroutine.
13881388
"""
1389-
if not asyncio.iscoroutinefunction(coro):
1389+
if not inspect.iscoroutinefunction(coro):
13901390
raise TypeError("The pre-invoke hook must be a coroutine.")
13911391

13921392
self._before_invoke = coro
@@ -1418,7 +1418,7 @@ def after_invoke(self, coro):
14181418
The coroutine passed is not actually a coroutine.
14191419
14201420
"""
1421-
if not asyncio.iscoroutinefunction(coro):
1421+
if not inspect.iscoroutinefunction(coro):
14221422
raise TypeError("The post-invoke hook must be a coroutine.")
14231423

14241424
self._after_invoke = coro

discord/client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from __future__ import annotations
2727

2828
import asyncio
29+
import inspect
2930
import logging
3031
import sys
3132
import traceback
@@ -1396,7 +1397,7 @@ async def my_message(message): pass
13961397
if not name.startswith("on_"):
13971398
raise ValueError("The 'name' parameter must start with 'on_'")
13981399

1399-
if not asyncio.iscoroutinefunction(func):
1400+
if not inspect.iscoroutinefunction(func):
14001401
raise TypeError("Listeners must be coroutines")
14011402

14021403
if name in self._event_handlers:
@@ -1476,7 +1477,7 @@ def decorator(func: Coro) -> Coro:
14761477
self.add_listener(func, name)
14771478
return func
14781479

1479-
if asyncio.iscoroutinefunction(name):
1480+
if inspect.iscoroutinefunction(name):
14801481
coro = name
14811482
name = coro.__name__
14821483
return decorator(coro)
@@ -1511,7 +1512,7 @@ async def on_ready():
15111512
print('Ready!')
15121513
"""
15131514

1514-
if not asyncio.iscoroutinefunction(coro):
1515+
if not inspect.iscoroutinefunction(coro):
15151516
raise TypeError("event registered must be a coroutine function")
15161517

15171518
setattr(self, coro.__name__, coro)

discord/commands/core.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ def error(self, coro):
503503
The coroutine passed is not actually a coroutine.
504504
"""
505505

506-
if not asyncio.iscoroutinefunction(coro):
506+
if not inspect.iscoroutinefunction(coro):
507507
raise TypeError("The error handler must be a coroutine.")
508508

509509
self.on_error = coro
@@ -532,7 +532,7 @@ def before_invoke(self, coro):
532532
TypeError
533533
The coroutine passed is not actually a coroutine.
534534
"""
535-
if not asyncio.iscoroutinefunction(coro):
535+
if not inspect.iscoroutinefunction(coro):
536536
raise TypeError("The pre-invoke hook must be a coroutine.")
537537

538538
self._before_invoke = coro
@@ -557,7 +557,7 @@ def after_invoke(self, coro):
557557
TypeError
558558
The coroutine passed is not actually a coroutine.
559559
"""
560-
if not asyncio.iscoroutinefunction(coro):
560+
if not inspect.iscoroutinefunction(coro):
561561
raise TypeError("The post-invoke hook must be a coroutine.")
562562

563563
self._after_invoke = coro
@@ -734,7 +734,7 @@ def __new__(cls, *args, **kwargs) -> SlashCommand:
734734

735735
def __init__(self, func: Callable, *args, **kwargs) -> None:
736736
super().__init__(func, **kwargs)
737-
if not asyncio.iscoroutinefunction(func):
737+
if not inspect.iscoroutinefunction(func):
738738
raise TypeError("Callback must be a coroutine.")
739739
self.callback = func
740740

@@ -1125,7 +1125,7 @@ async def invoke_autocomplete_callback(self, ctx: AutocompleteContext):
11251125
else:
11261126
result = option.autocomplete(ctx)
11271127

1128-
if asyncio.iscoroutinefunction(option.autocomplete):
1128+
if inspect.iscoroutinefunction(option.autocomplete):
11291129
result = await result
11301130

11311131
choices = [
@@ -1653,7 +1653,7 @@ def __new__(cls, *args, **kwargs) -> ContextMenuCommand:
16531653

16541654
def __init__(self, func: Callable, *args, **kwargs) -> None:
16551655
super().__init__(func, **kwargs)
1656-
if not asyncio.iscoroutinefunction(func):
1656+
if not inspect.iscoroutinefunction(func):
16571657
raise TypeError("Callback must be a coroutine.")
16581658
self.callback = func
16591659

discord/ext/commands/core.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def __init__(
325325
),
326326
**kwargs: Any,
327327
):
328-
if not asyncio.iscoroutinefunction(func):
328+
if not inspect.iscoroutinefunction(func):
329329
raise TypeError("Callback must be a coroutine.")
330330

331331
name = kwargs.get("name") or func.__name__
@@ -993,7 +993,7 @@ def error(self, coro: ErrorT) -> ErrorT:
993993
The coroutine passed is not actually a coroutine.
994994
"""
995995

996-
if not asyncio.iscoroutinefunction(coro):
996+
if not inspect.iscoroutinefunction(coro):
997997
raise TypeError("The error handler must be a coroutine.")
998998

999999
self.on_error: Error = coro
@@ -1027,7 +1027,7 @@ def before_invoke(self, coro: HookT) -> HookT:
10271027
TypeError
10281028
The coroutine passed is not actually a coroutine.
10291029
"""
1030-
if not asyncio.iscoroutinefunction(coro):
1030+
if not inspect.iscoroutinefunction(coro):
10311031
raise TypeError("The pre-invoke hook must be a coroutine.")
10321032

10331033
self._before_invoke = coro
@@ -1054,7 +1054,7 @@ def after_invoke(self, coro: HookT) -> HookT:
10541054
TypeError
10551055
The coroutine passed is not actually a coroutine.
10561056
"""
1057-
if not asyncio.iscoroutinefunction(coro):
1057+
if not inspect.iscoroutinefunction(coro):
10581058
raise TypeError("The post-invoke hook must be a coroutine.")
10591059

10601060
self._after_invoke = coro

discord/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import datetime
3232
import functools
3333
import importlib.resources
34+
import inspect
3435
import itertools
3536
import json
3637
import logging
@@ -1377,7 +1378,7 @@ def _filter(ctx: AutocompleteContext, item: Any) -> bool:
13771378

13781379
gen = (val for val in _values if _filter(ctx, val))
13791380

1380-
elif asyncio.iscoroutinefunction(filter):
1381+
elif inspect.iscoroutinefunction(filter):
13811382
gen = (val for val in _values if await filter(ctx, val))
13821383

13831384
elif callable(filter):

0 commit comments

Comments
 (0)