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

IndexError: pop from empty list while calling pop_screen #3041

Closed
mzebrak opened this issue Aug 1, 2023 · 4 comments
Closed

IndexError: pop from empty list while calling pop_screen #3041

mzebrak opened this issue Aug 1, 2023 · 4 comments

Comments

@mzebrak
Copy link

mzebrak commented Aug 1, 2023

Textual version of 0.30.0

Related: #2650

/lib/python3.10/site-packages/textual/app.py:1732 in                                                                               │
│ pop_screen                                                                                                                       │
│                                                                                                                                  │
│   1729 │   │   │   │   "Can't pop screen; there must be at least one screen on the stack"                                        │
│   1730 │   │   │   )                                                                                                             │
│   1731 │   │   previous_screen = self._replace_screen(screen_stack.pop())                                                        │
│ ❱ 1732 │   │   previous_screen._pop_result_callback()                                                                            │
│   1733 │   │   self.screen._screen_resized(self.size)                                                                            │
│   1734 │   │   self.screen.post_message(events.ScreenResume())                                                                   │
│   1735 │   │   self.log.system(f"{self.screen} is active")                                                                       │
│                                                                                                                                  │
│                                                                                                                                  │
│/lib/python3.10/site-packages/textual/screen.py:635 in                                                                            │
│ _pop_result_callback                                                                                                             │
│                                                                                                                                  │
│   632 │                                                                                        ╭─── locals ────╮                 │
│   633 │   def _pop_result_callback(self) -> None:                                              │ self = Cart() │                 │
│   634 │   │   """Remove the latest result callback from the stack."""                          ╰───────────────╯                 │
│ ❱ 635 │   │   self._result_callbacks.pop()                                                                                       │
│   636 │                                                                                                                          │
│   637 │   def _refresh_layout(                                                                                                   │
│   638 │   │   self, size: Size | None = None, full: bool = False, scroll: bool = False                                           │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
IndexError: pop from empty list

I think it's related to the switch_screen call with "screen" as str and not Screen instance
My logging includes "with screen as string" postfix when push_screen or switch_screen is called with "screen" as str
Here's the sequence:

2023-07-31 12:43:03.893 | ⚠️ WARNING  | Textual issue with _pop_result_callback: push_screen called 
2023-07-31 12:43:03.895 | ⚠️ WARNING  | Textual issue with _pop_result_callback: push_screen called 
2023-07-31 12:43:04.438 | ⚠️ WARNING  | Textual issue with _pop_result_callback: push_screen called 
2023-07-31 12:43:05.852 | ⚠️ WARNING  | Textual issue with _pop_result_callback: push_screen called 
2023-07-31 12:43:08.068 | ⚠️ WARNING  | Textual issue with _pop_result_callback: push_screen called 
2023-07-31 12:43:09.302 | ⚠️ WARNING  | Textual issue with _pop_result_callback: push_screen called 
2023-07-31 12:43:11.912 | ⚠️ WARNING  | Textual issue with _pop_result_callback: push_screen called 
2023-07-31 12:43:13.077 | ⚠️ WARNING  | Textual issue with _pop_result_callback: push_screen called 
2023-07-31 12:43:14.283 | ⚠️ WARNING  | Textual issue with _pop_result_callback: pop_screen called
2023-07-31 12:43:14.301 | ⚠️ WARNING  | Textual issue with _pop_result_callback: pop_screen called
2023-07-31 12:43:14.315 | ⚠️ WARNING  | Textual issue with _pop_result_callback: pop_screen called
2023-07-31 12:43:14.330 | ⚠️ WARNING  | Textual issue with _pop_result_callback: pop_screen called
2023-07-31 12:43:14.341 | ⚠️ WARNING  | Textual issue with _pop_result_callback: pop_screen called
2023-07-31 12:43:14.350 | ⚠️ WARNING  | Textual issue with _pop_result_callback: pop_screen called
2023-07-31 12:43:14.353 | ⚠️ WARNING  | Textual issue with _pop_result_callback: pop_screen called
2023-07-31 12:43:14.422 | ⚠️ WARNING  | Textual issue with _pop_result_callback: switch_screen called with screen as string
2023-07-31 12:43:16.090 | ⚠️ WARNING  | Textual issue with _pop_result_callback: push_screen called 
2023-07-31 12:43:19.593 | ⚠️ WARNING  | Textual issue with _pop_result_callback: push_screen called 
2023-07-31 12:43:31.498 | ⚠️ WARNING  | Textual issue with _pop_result_callback: switch_screen called 
2023-07-31 12:43:34.968 | ⚠️ WARNING  | Textual issue with _pop_result_callback: pop_screen called
2023-07-31 12:43:35.002 | ⚠️ WARNING  | Textual issue with _pop_result_callback: pop_screen called
@github-actions
Copy link

github-actions bot commented Aug 1, 2023

We found the following entry in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

@mzebrak
Copy link
Author

mzebrak commented Aug 1, 2023

Alright, I investigated it a little bit more and this is not related to the Textual itself, it's an issue with our implementation that uses private parts of Textual but please give me a minute to explain because it is an interesting problem, and to be more precise, it is another problem related to the lack of an interface to dynamically change bindings.

Explanation:

The issue comes directly from: #1792

Because we had to define 2 classes for the same screen, just with different bindings like DashboardActive and DashboardInactive.

This caused another problem - we had to take care of replacing the dashboard screen (which is always located at the bottom of the screen_stack), depending on whether the application is in active or inactive mode.

So we prepared a couple of methods for that like replace_screen ( which is different than switch_screen because it searches for the given old screen and replaces with the new given screen). And this method internally used another method:

    def push_screen_at(self, index: int, screen: str | Screen[ScreenResultType]) -> None:
        """Push a screen at the given index in the stack."""
        screen_, _ = self.app._get_screen(screen)
        # screen_._push_result_callback(None, None)  # After updating textual to the newest version we had this line missing.
        self.app._screen_stack.insert(index, screen_)

So it seems to me that you can notice an interesting problem here, which is not entirely clear how to solve - due to the lack of the possibility to use dynamic bindings and the lack of appropriate methods for better management of screens (like the two mentioned above) such problems appear. If there is already a recommended path, please point me to it, but it seems to me that there is no solution for this type of problem yet, because I follow the textual status quite closely.

I would like to ask you @willmcgugan to refer to this topic, perhaps my problem will help to notice the deficiencies in the textual, or will outline a path for others how to deal with such a situation.

@willmcgugan
Copy link
Collaborator

Closing as its not a Textual issue.

Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

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

No branches or pull requests

2 participants