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

Fix refreshable with function references #1313

Merged
merged 1 commit into from
Aug 2, 2023
Merged

Fix refreshable with function references #1313

merged 1 commit into from
Aug 2, 2023

Conversation

falkoschindler
Copy link
Contributor

This PR fixes #1283. It can be tested with the following example:

class Test:

    def __init__(self, name):
        self.name = name
        self.ui()

    @ui.refreshable
    def ui(self):
        ui.notify(f'Refreshing {self.name}')
        ui.button(self.name, on_click=self.ui.refresh)

Test('A')
Test('B')

Since the click handler holds a direct reference to the static refresh function, the instance isn't updated via __get__ when the button is clicked. Therefore this PR uses __getattribute__ to intercept when the refresh function is accessed while creating the button. It wraps refresh with the instance bound to the wrapper function. This way it always uses the right reference once the button is clicked.

@falkoschindler falkoschindler added this to the 1.3.7 milestone Aug 2, 2023
@falkoschindler falkoschindler added the bug Something isn't working label Aug 2, 2023
Copy link
Member

@rodja rodja left a comment

Choose a reason for hiding this comment

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

Smart

@rodja rodja merged commit 30545aa into main Aug 2, 2023
5 checks passed
@rodja rodja deleted the refreshable branch August 2, 2023 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ui.refreshable updating the wrong element
2 participants