Textualize / textual

The lean application framework for Python. Build sophisticated user interfaces with a simple Python API. Run your apps in the terminal and a web browser.
https://textual.textualize.io/
MIT License
25.15k stars 770 forks source link

Using `dismiss` in `call_after_refresh` now raises an error. #5049

Open JoeZiminski opened 2 hours ago

JoeZiminski commented 2 hours ago

I just wanted to highlight change in behaviour that I could not see documented in the change log. Previously I was calling call_after_refresh(lambda: self.dismiss(True)) within a ModalScreen. Now, this gives an error:

ScreenError: Can't await screen.dismiss() from the screen's message handler; try removing the await

I think because of a new check where this error is raised. I found another workaround to acheive what I wanted, but thought I'd raise this in case 1) this change in behaviour was not intended 2) an improved error mesage could be given. It took me a while to track it down, if suitable, if the error could indicate not to use self.dismiss in call_after_refresh it might be useful.

Sorry I cannot give clear versions on which this works / does not work. But it is OK in 0.71.0 but not in most recent version.

github-actions[bot] commented 2 hours ago

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

TomJGooding commented 1 hour ago

I'm not sure what may have changed, but why use a lambda rather than call_after_refresh(self.dismiss, True)?

EDIT: Never mind, after taking a closer look I think this changed in #4789 with the warning below added to the dismiss docs. But I'm also struggling to understand this warning and the error message in the context of dismissing a screen after it has refreshed.

Textual will raise a ScreenError if you await the return value from a message handler on the Screen being dismissed. If you want to dismiss the current screen, you can call self.dismiss() without awaiting.