Skip to content

Commit f7bb866

Browse files
authored
Merge pull request #3545 from brandonschabell/feature/coroutine-deprecation
Replace deprecated asyncio.iscoroutinefunction() call with inspect.iscoroutinefunction()
2 parents 502997d + 4e2d717 commit f7bb866

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

dash/_callback.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import collections
22
import hashlib
3+
import inspect
34
from functools import wraps
45

56
from typing import Callable, Optional, Any, List, Tuple, Union, Dict
67

7-
8-
import asyncio
98
import flask
109

1110
from .dependencies import (
@@ -49,7 +48,7 @@ async def _async_invoke_callback(
4948
func, *args, **kwargs
5049
): # used to mark the frame for the debugger
5150
# Check if the function is a coroutine function
52-
if asyncio.iscoroutinefunction(func):
51+
if inspect.iscoroutinefunction(func):
5352
return await func(*args, **kwargs) # %% callback invoked %%
5453
# If the function is not a coroutine, call it directly
5554
return func(*args, **kwargs) # %% callback invoked %%
@@ -814,7 +813,7 @@ async def async_add_context(*args, **kwargs):
814813

815814
return jsonResponse
816815

817-
if asyncio.iscoroutinefunction(func):
816+
if inspect.iscoroutinefunction(func):
818817
callback_map[callback_id]["callback"] = async_add_context
819818
else:
820819
callback_map[callback_id]["callback"] = add_context

dash/_jupyter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def capture_event(stream, ident, parent):
202202
if _jupyter_comm_response_received():
203203
break
204204

205-
if asyncio.iscoroutinefunction(kernel.do_one_iteration):
205+
if inspect.iscoroutinefunction(kernel.do_one_iteration):
206206
loop = asyncio.get_event_loop()
207207
nest_asyncio.apply(loop)
208208
loop.run_until_complete(kernel.do_one_iteration())

dash/background_callback/managers/celery_manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import inspect
12
import json
23
import traceback
34
from contextvars import copy_context
@@ -250,7 +251,7 @@ async def async_run():
250251
result_key, json.dumps(user_callback_output, cls=PlotlyJSONEncoder)
251252
)
252253

253-
if asyncio.iscoroutinefunction(fn):
254+
if inspect.iscoroutinefunction(fn):
254255
func = partial(ctx.run, async_run)
255256
asyncio.run(func())
256257
else:

dash/background_callback/managers/diskcache_manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import inspect
12
import traceback
23
from contextvars import copy_context
34
import asyncio
@@ -296,7 +297,7 @@ async def async_run():
296297
except Exception as err: # pylint: disable=broad-except
297298
print(f"Diskcache manager couldn't save output: {err}")
298299

299-
if asyncio.iscoroutinefunction(fn):
300+
if inspect.iscoroutinefunction(fn):
300301
func = partial(ctx.run, async_run)
301302
asyncio.run(func())
302303
else:

dash/dash.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import sys
44
import collections
5+
import inspect
56
import importlib
67
import warnings
78
from contextvars import copy_context
@@ -220,7 +221,7 @@ def _do_skip(error):
220221

221222
async def execute_async_function(func, *args, **kwargs):
222223
# Check if the function is a coroutine function
223-
if asyncio.iscoroutinefunction(func):
224+
if inspect.iscoroutinefunction(func):
224225
return await func(*args, **kwargs)
225226
# If the function is not a coroutine, call it directly
226227
return func(*args, **kwargs)
@@ -837,7 +838,7 @@ async def _parse_body_async():
837838
return _parse_body_async
838839

839840
for path, func in self.callback_api_paths.items():
840-
if asyncio.iscoroutinefunction(func):
841+
if inspect.iscoroutinefunction(func):
841842
self._add_url(path, make_parse_body_async(func), ["POST"])
842843
else:
843844
self._add_url(path, make_parse_body(func), ["POST"])

0 commit comments

Comments
 (0)