Skip to content

Commit e50f75c

Browse files
Replace asyncio.iscoroutinefunction with inspect.iscoroutinefunction
Fixes `DeprecationWarning` on Python 3.14, although for now we still get them from `pytest-asyncio`; `asyncio.iscoroutinefunction` is scheduled for removal in Python 3.16. https://docs.python.org/3.13/library/inspect.html#inspect.iscoroutinefunction
1 parent a6e5d92 commit e50f75c

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

src/engineio/async_client.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import inspect
23
import signal
34
import ssl
45
import threading
@@ -456,7 +457,7 @@ async def _trigger_event(self, event, *args, **kwargs):
456457
run_async = kwargs.pop('run_async', False)
457458
ret = None
458459
if event in self.handlers:
459-
if asyncio.iscoroutinefunction(self.handlers[event]) is True:
460+
if inspect.iscoroutinefunction(self.handlers[event]) is True:
460461
if run_async:
461462
task = self.start_background_task(self.handlers[event],
462463
*args)

src/engineio/async_drivers/aiohttp.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import asyncio
1+
import inspect
22
import sys
33
from urllib.parse import urlsplit
44

@@ -105,7 +105,7 @@ async def send(self, message):
105105
f = self._sock.send_bytes
106106
else:
107107
f = self._sock.send_str
108-
if asyncio.iscoroutinefunction(f):
108+
if inspect.iscoroutinefunction(f):
109109
await f(message)
110110
else:
111111
f(message)

src/engineio/async_drivers/asgi.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import sys
3-
import asyncio
3+
import inspect
44

55
from engineio.static_files import get_static_file
66

@@ -102,7 +102,7 @@ async def lifespan(self, scope, receive, send):
102102
if self.on_startup:
103103
try:
104104
await self.on_startup() \
105-
if asyncio.iscoroutinefunction(self.on_startup) \
105+
if inspect.iscoroutinefunction(self.on_startup) \
106106
else self.on_startup()
107107
except:
108108
await send({'type': 'lifespan.startup.failed'})
@@ -112,7 +112,7 @@ async def lifespan(self, scope, receive, send):
112112
if self.on_shutdown:
113113
try:
114114
await self.on_shutdown() \
115-
if asyncio.iscoroutinefunction(self.on_shutdown) \
115+
if inspect.iscoroutinefunction(self.on_shutdown) \
116116
else self.on_shutdown()
117117
except:
118118
await send({'type': 'lifespan.shutdown.failed'})

src/engineio/async_server.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import inspect
23
import urllib
34

45
from . import base_server
@@ -209,7 +210,7 @@ async def handle_request(self, *args, **kwargs):
209210
Note: this method is a coroutine.
210211
"""
211212
translate_request = self._async['translate_request']
212-
if asyncio.iscoroutinefunction(translate_request):
213+
if inspect.iscoroutinefunction(translate_request):
213214
environ = await translate_request(*args, **kwargs)
214215
else:
215216
environ = translate_request(*args, **kwargs)
@@ -416,7 +417,7 @@ def create_event(self, *args, **kwargs):
416417
async def _make_response(self, response_dict, environ):
417418
cors_headers = self._cors_headers(environ)
418419
make_response = self._async['make_response']
419-
if asyncio.iscoroutinefunction(make_response):
420+
if inspect.iscoroutinefunction(make_response):
420421
response = await make_response(
421422
response_dict['status'],
422423
response_dict['headers'] + cors_headers,
@@ -488,7 +489,7 @@ async def _trigger_event(self, event, *args, **kwargs):
488489
run_async = kwargs.pop('run_async', False)
489490
ret = None
490491
if event in self.handlers:
491-
if asyncio.iscoroutinefunction(self.handlers[event]):
492+
if inspect.iscoroutinefunction(self.handlers[event]):
492493
async def run_async_handler():
493494
try:
494495
return await self.handlers[event](*args)

0 commit comments

Comments
 (0)