Skip to content
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

Handle async functions in bind #3264

Merged
merged 1 commit into from
Mar 26, 2022
Merged
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
18 changes: 15 additions & 3 deletions panel/depends.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import param

from param.parameterized import iscoroutinefunction

from .widgets import Widget

ipywidget_classes = {}
Expand Down Expand Up @@ -148,8 +150,7 @@ def _param_bind(function, *args, watch=False, **kwargs):
elif isinstance(p, param.Parameter):
dependencies[kw] = p

@depends(**dependencies, watch=watch)
def wrapped(*wargs, **wkwargs):
def combine_arguments(wargs, wkwargs):
combined_args = []
for arg in args:
if hasattr(arg, '_dinfo'):
Expand All @@ -169,5 +170,16 @@ def wrapped(*wargs, **wkwargs):
if kw.startswith('__arg') or kw.startswith('__kwarg'):
continue
combined_kwargs[kw] = arg
return function(*combined_args, **combined_kwargs)
return combined_args, combined_kwargs

if iscoroutinefunction(function):
@depends(**dependencies, watch=watch)
async def wrapped(*wargs, **wkwargs):
combined_args, combined_kwargs = combine_arguments(wargs, wkwargs)
return await function(*combined_args, **combined_kwargs)
else:
@depends(**dependencies, watch=watch)
def wrapped(*wargs, **wkwargs):
combined_args, combined_kwargs = combine_arguments(wargs, wkwargs)
return function(*combined_args, **combined_kwargs)
return wrapped