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
7 changes: 3 additions & 4 deletions dash/_callback.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import collections
import hashlib
import inspect
from functools import wraps

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


import asyncio
import flask

from .dependencies import (
Expand Down Expand Up @@ -49,7 +48,7 @@ async def _async_invoke_callback(
func, *args, **kwargs
): # used to mark the frame for the debugger
# Check if the function is a coroutine function
if asyncio.iscoroutinefunction(func):
if inspect.iscoroutinefunction(func):
return await func(*args, **kwargs) # %% callback invoked %%
# If the function is not a coroutine, call it directly
return func(*args, **kwargs) # %% callback invoked %%
Expand Down Expand Up @@ -814,7 +813,7 @@ async def async_add_context(*args, **kwargs):

return jsonResponse

if asyncio.iscoroutinefunction(func):
if inspect.iscoroutinefunction(func):
callback_map[callback_id]["callback"] = async_add_context
else:
callback_map[callback_id]["callback"] = add_context
Expand Down
2 changes: 1 addition & 1 deletion dash/_jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def capture_event(stream, ident, parent):
if _jupyter_comm_response_received():
break

if asyncio.iscoroutinefunction(kernel.do_one_iteration):
if inspect.iscoroutinefunction(kernel.do_one_iteration):
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inspect module is not imported in this file. Add import inspect at the top of the file to avoid a NameError at runtime.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's imported on line 3 😄

loop = asyncio.get_event_loop()
nest_asyncio.apply(loop)
loop.run_until_complete(kernel.do_one_iteration())
Expand Down
3 changes: 2 additions & 1 deletion dash/background_callback/managers/celery_manager.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import inspect
import json
import traceback
from contextvars import copy_context
Expand Down Expand Up @@ -250,7 +251,7 @@ async def async_run():
result_key, json.dumps(user_callback_output, cls=PlotlyJSONEncoder)
)

if asyncio.iscoroutinefunction(fn):
if inspect.iscoroutinefunction(fn):
func = partial(ctx.run, async_run)
asyncio.run(func())
else:
Expand Down
3 changes: 2 additions & 1 deletion dash/background_callback/managers/diskcache_manager.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import inspect
import traceback
from contextvars import copy_context
import asyncio
Expand Down Expand Up @@ -296,7 +297,7 @@ async def async_run():
except Exception as err: # pylint: disable=broad-except
print(f"Diskcache manager couldn't save output: {err}")

if asyncio.iscoroutinefunction(fn):
if inspect.iscoroutinefunction(fn):
func = partial(ctx.run, async_run)
asyncio.run(func())
else:
Expand Down
5 changes: 3 additions & 2 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import sys
import collections
import inspect
import importlib
import warnings
from contextvars import copy_context
Expand Down Expand Up @@ -220,7 +221,7 @@ def _do_skip(error):

async def execute_async_function(func, *args, **kwargs):
# Check if the function is a coroutine function
if asyncio.iscoroutinefunction(func):
if inspect.iscoroutinefunction(func):
return await func(*args, **kwargs)
# If the function is not a coroutine, call it directly
return func(*args, **kwargs)
Expand Down Expand Up @@ -837,7 +838,7 @@ async def _parse_body_async():
return _parse_body_async

for path, func in self.callback_api_paths.items():
if asyncio.iscoroutinefunction(func):
if inspect.iscoroutinefunction(func):
self._add_url(path, make_parse_body_async(func), ["POST"])
else:
self._add_url(path, make_parse_body(func), ["POST"])
Expand Down
Loading