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

check if event handler has parameters without default value #965

Merged
merged 1 commit into from
May 28, 2023

Conversation

falkoschindler
Copy link
Contributor

This PR changes the way event handlers get called with or without event arguments. Consider this example:

ui.button('1', on_click=lambda: ui.notify('1'))
ui.button('2', on_click=lambda _, x=2: ui.notify(x))
ui.button('3', on_click=lambda x=3: ui.notify(x))

In the last case, event arguments have been passed to x because the event handler does expect arguments. With this PR, however, x remains set to 3, because the event handler does not expect any argument without a default value.

I think this is a reasonable distinction, because a parameter with a default value most certainly won't accept event arguments. And it helps in cases like https://stackoverflow.com/q/76348605/3419103 where local variables need to get captured in a lambda statement. Filling those parameters with event arguments confuses many users.

@falkoschindler falkoschindler self-assigned this May 28, 2023
@falkoschindler falkoschindler requested a review from rodja May 28, 2023 07:40
@falkoschindler falkoschindler added this to the 1.2.16 milestone May 28, 2023
@falkoschindler falkoschindler merged commit 0c66b61 into main May 28, 2023
7 checks passed
@falkoschindler falkoschindler deleted the event_args branch May 28, 2023 13:02
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.

None yet

2 participants