Skip to content

Replace deprecated asyncio.iscoroutinefunction with its counterpart from inspect #10634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 30, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 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,15 @@ def __init__(
if expect_handler is None:
expect_handler = _default_expect_handler

assert asyncio.iscoroutinefunction(
assert inspect.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):
pass
elif isinstance(handler, type) and issubclass(handler, AbstractView):
pass
Expand Down
3 changes: 2 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,7 @@ 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):
wsgi = await self.wsgi()
if isinstance(wsgi, web.AppRunner):
runner = wsgi
Expand Down
Loading