Avoid throwing if Pyodide does not await due missing arguments (#2158)

* Fix #2156 - Avoid requiring args for async functions

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Andrea Giammarchi
2024-09-06 15:16:28 +02:00
committed by GitHub
parent e525d54be0
commit c8c2dd0806

View File

@@ -41,8 +41,16 @@ def when(event_type=None, selector=None):
# Function doesn't receive events
if not sig.parameters:
def wrapper(*args, **kwargs):
func()
# Function is async: must be awaited
if inspect.iscoroutinefunction(func):
async def wrapper(*args, **kwargs):
await func()
else:
def wrapper(*args, **kwargs):
func()
else:
wrapper = func