Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES/10634.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Replaced deprecated ``asyncio.iscoroutinefunction`` with its counterpart from ``inspect``
-- by :user:`layday`.
6 changes: 3 additions & 3 deletions aiohttp/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def pytest_fixture_setup(fixturedef): # type: ignore[no-untyped-def]
if inspect.isasyncgenfunction(func):
# async generator fixture
is_async_gen = True
elif asyncio.iscoroutinefunction(func):
elif inspect.iscoroutinefunction(func):
# regular async fixture
is_async_gen = False
else:
Expand Down Expand Up @@ -216,14 +216,14 @@ def _passthrough_loop_context(

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


def pytest_pyfunc_call(pyfuncitem): # type: ignore[no-untyped-def]
"""Run coroutines in an event loop instead of a normal function call."""
fast = pyfuncitem.config.getoption("--aiohttp-fast")
if asyncio.iscoroutinefunction(pyfuncitem.function):
if inspect.iscoroutinefunction(pyfuncitem.function):
existing_loop = pyfuncitem.funcargs.get(
"proactor_loop"
) or pyfuncitem.funcargs.get("loop", None)
Expand Down
9 changes: 6 additions & 3 deletions aiohttp/web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import functools
import hashlib
import html
import inspect
import keyword
import os
import re
Expand Down Expand Up @@ -174,15 +175,17 @@ def __init__(
if expect_handler is None:
expect_handler = _default_expect_handler

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

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

if asyncio.iscoroutinefunction(handler):
if inspect.iscoroutinefunction(handler) or (
sys.version_info < (3, 14) and asyncio.iscoroutinefunction(handler)
):
pass
elif isinstance(handler, type) and issubclass(handler, AbstractView):
pass
Expand Down
5 changes: 4 additions & 1 deletion aiohttp/worker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Async gunicorn worker for aiohttp.web"""

import asyncio
import inspect
import os
import re
import signal
Expand Down Expand Up @@ -68,7 +69,9 @@ async def _run(self) -> None:
runner = None
if isinstance(self.wsgi, Application):
app = self.wsgi
elif asyncio.iscoroutinefunction(self.wsgi):
elif inspect.iscoroutinefunction(self.wsgi) or (
sys.version_info < (3, 14) and asyncio.iscoroutinefunction(self.wsgi)
):
wsgi = await self.wsgi()
if isinstance(wsgi, web.AppRunner):
runner = wsgi
Expand Down
Loading