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

Conversation

WebReflection
Copy link
Contributor

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.

This MR fixes that by using the right introspection to decide how the wrapper should be defined (that is: either async or sync).

Changes

  • define an async wrapper when the given function is async too
  • test all conditions (manually) that everything works:
    • test async def click() and async def click(event) after @when
    • test def click() and def click(event) after @when

Checklist

  • All tests pass locally
  • I have updated CHANGELOG.md
  • I have created documentation for this(if applicable)

@WebReflection WebReflection requested a review from ntoll September 6, 2024 12:55
@WebReflection WebReflection force-pushed the discussion-2156-2 branch 2 times, most recently from 0bd1953 to f923602 Compare September 6, 2024 12:56
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.

😄

@WebReflection WebReflection merged commit c8c2dd0 into pyscript:main Sep 6, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants