Skip to content

Commit 1efe72f

Browse files
committed
Replace asyncio.iscoroutinefunction with inspect.iscoroutinefunction
`asyncio.iscoroutinefunction` was deprecated in python/cpython#122875.
1 parent e66b5fe commit 1efe72f

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

aiohttp/pytest_plugin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def pytest_fixture_setup(fixturedef): # type: ignore[no-untyped-def]
106106
if inspect.isasyncgenfunction(func):
107107
# async generator fixture
108108
is_async_gen = True
109-
elif asyncio.iscoroutinefunction(func):
109+
elif inspect.iscoroutinefunction(func):
110110
# regular async fixture
111111
is_async_gen = False
112112
else:
@@ -216,14 +216,14 @@ def _passthrough_loop_context(
216216

217217
def pytest_pycollect_makeitem(collector, name, obj): # type: ignore[no-untyped-def]
218218
"""Fix pytest collecting for coroutines."""
219-
if collector.funcnamefilter(name) and asyncio.iscoroutinefunction(obj):
219+
if collector.funcnamefilter(name) and inspect.iscoroutinefunction(obj):
220220
return list(collector._genfunctions(name, obj))
221221

222222

223223
def pytest_pyfunc_call(pyfuncitem): # type: ignore[no-untyped-def]
224224
"""Run coroutines in an event loop instead of a normal function call."""
225225
fast = pyfuncitem.config.getoption("--aiohttp-fast")
226-
if asyncio.iscoroutinefunction(pyfuncitem.function):
226+
if inspect.iscoroutinefunction(pyfuncitem.function):
227227
existing_loop = pyfuncitem.funcargs.get(
228228
"proactor_loop"
229229
) or pyfuncitem.funcargs.get("loop", None)

aiohttp/web_urldispatcher.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import functools
55
import hashlib
66
import html
7+
import inspect
78
import keyword
89
import os
910
import re
@@ -174,15 +175,15 @@ def __init__(
174175
if expect_handler is None:
175176
expect_handler = _default_expect_handler
176177

177-
assert asyncio.iscoroutinefunction(
178+
assert inspect.iscoroutinefunction(
178179
expect_handler
179180
), f"Coroutine is expected, got {expect_handler!r}"
180181

181182
method = method.upper()
182183
if not HTTP_METHOD_RE.match(method):
183184
raise ValueError(f"{method} is not allowed HTTP method")
184185

185-
if asyncio.iscoroutinefunction(handler):
186+
if inspect.iscoroutinefunction(handler):
186187
pass
187188
elif isinstance(handler, type) and issubclass(handler, AbstractView):
188189
pass

aiohttp/worker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Async gunicorn worker for aiohttp.web"""
22

33
import asyncio
4+
import inspect
45
import os
56
import re
67
import signal
@@ -68,7 +69,7 @@ async def _run(self) -> None:
6869
runner = None
6970
if isinstance(self.wsgi, Application):
7071
app = self.wsgi
71-
elif asyncio.iscoroutinefunction(self.wsgi):
72+
elif inspect.iscoroutinefunction(self.wsgi):
7273
wsgi = await self.wsgi()
7374
if isinstance(wsgi, web.AppRunner):
7475
runner = wsgi

0 commit comments

Comments
 (0)