Skip to content

Commit 4f999f2

Browse files
committed
Replace deprecated asyncio.iscoroutinefunction with its counterpart from inspect (aio-libs#10634)
(cherry picked from commit 77ad7d7)
1 parent 2082fba commit 4f999f2

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

Diff for: CHANGES/10634.bugfix.rst

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Replaced deprecated ``asyncio.iscoroutinefunction`` with its counterpart from ``inspect``
2+
-- by :user:`layday`.

Diff for: aiohttp/pytest_plugin.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def pytest_fixture_setup(fixturedef): # type: ignore[no-untyped-def]
9898
if inspect.isasyncgenfunction(func):
9999
# async generator fixture
100100
is_async_gen = True
101-
elif asyncio.iscoroutinefunction(func):
101+
elif inspect.iscoroutinefunction(func):
102102
# regular async fixture
103103
is_async_gen = False
104104
else:
@@ -200,14 +200,14 @@ def _passthrough_loop_context(loop, fast=False): # type: ignore[no-untyped-def]
200200

201201
def pytest_pycollect_makeitem(collector, name, obj): # type: ignore[no-untyped-def]
202202
"""Fix pytest collecting for coroutines."""
203-
if collector.funcnamefilter(name) and asyncio.iscoroutinefunction(obj):
203+
if collector.funcnamefilter(name) and inspect.iscoroutinefunction(obj):
204204
return list(collector._genfunctions(name, obj))
205205

206206

207207
def pytest_pyfunc_call(pyfuncitem): # type: ignore[no-untyped-def]
208208
"""Run coroutines in an event loop instead of a normal function call."""
209209
fast = pyfuncitem.config.getoption("--aiohttp-fast")
210-
if asyncio.iscoroutinefunction(pyfuncitem.function):
210+
if inspect.iscoroutinefunction(pyfuncitem.function):
211211
existing_loop = pyfuncitem.funcargs.get(
212212
"proactor_loop"
213213
) or pyfuncitem.funcargs.get("loop", None)

Diff for: aiohttp/web_urldispatcher.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,18 @@ def __init__(
180180
if expect_handler is None:
181181
expect_handler = _default_expect_handler
182182

183-
assert asyncio.iscoroutinefunction(
184-
expect_handler
183+
assert inspect.iscoroutinefunction(expect_handler) or (
184+
sys.version_info < (3, 14) and asyncio.iscoroutinefunction(expect_handler)
185185
), f"Coroutine is expected, got {expect_handler!r}"
186186

187187
method = method.upper()
188188
if not HTTP_METHOD_RE.match(method):
189189
raise ValueError(f"{method} is not allowed HTTP method")
190190

191191
assert callable(handler), handler
192-
if asyncio.iscoroutinefunction(handler):
192+
if inspect.iscoroutinefunction(handler) or (
193+
sys.version_info < (3, 14) and asyncio.iscoroutinefunction(handler)
194+
):
193195
pass
194196
elif inspect.isgeneratorfunction(handler):
195197
warnings.warn(

Diff for: aiohttp/worker.py

+4-1
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
@@ -71,7 +72,9 @@ async def _run(self) -> None:
7172
runner = None
7273
if isinstance(self.wsgi, Application):
7374
app = self.wsgi
74-
elif asyncio.iscoroutinefunction(self.wsgi):
75+
elif inspect.iscoroutinefunction(self.wsgi) or (
76+
sys.version_info < (3, 14) and asyncio.iscoroutinefunction(self.wsgi)
77+
):
7578
wsgi = await self.wsgi()
7679
if isinstance(wsgi, web.AppRunner):
7780
runner = wsgi

0 commit comments

Comments
 (0)