Skip to content

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

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

Merged
merged 2 commits into from
Sep 6, 2024
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
12 changes: 10 additions & 2 deletions pyscript.core/src/stdlib/pyscript/event_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,16 @@ def decorator(func):
# Function doesn't receive events
if not sig.parameters:

def wrapper(*args, **kwargs):
func()
# Function is async: must be awaited
if inspect.iscoroutinefunction(func):
Copy link
Member

Choose a reason for hiding this comment

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

Interestingly, this bit of code only ever runs in Pyodide (see the ugly hack comment elsewhere in this function).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's Pyodide only that has issues when no args are passed indeed and MicroPython doesn't need any of this and it works out of the box 🤷

Copy link
Contributor Author

@WebReflection WebReflection Sep 6, 2024

Choose a reason for hiding this comment

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

just in case, it was literally in this MR description:

In Pyodide (only) use case when a function has no args but it's async, the wrapper is not asynchronous and it doesn't await the passed callback. This results into hard to understand errors otherwise not present in MicroPython.

😄


async def wrapper(*args, **kwargs):
await func()

else:

def wrapper(*args, **kwargs):
func()

else:
wrapper = func
Expand Down