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

An empty OptionList with width: auto causes a crash in get_content_width #5489

Open
davep opened this issue Jan 20, 2025 · 0 comments · May be fixed by #5492
Open

An empty OptionList with width: auto causes a crash in get_content_width #5489

davep opened this issue Jan 20, 2025 · 0 comments · May be fixed by #5492

Comments

@davep
Copy link
Contributor

davep commented Jan 20, 2025

This code:

from textual.app import App, ComposeResult
from textual.widgets import OptionList

class OptionListAutoCrash(App[None]):

    CSS = """
    OptionList {
        width: auto;
    }
    """

    def compose(self) -> ComposeResult:
        yield OptionList()

if __name__ == "__main__":
    OptionListAutoCrash().run()

results in this crash:

│ /Users/davep/temp/x/.venv/lib/python3.13/site-packages/textual/widgets/_option_list.py:396 in get_content_width                                       │
│                                                                                                                                                       │
│    393 │   │   """Get maximum width of options."""                                                                                                    │
│    394 │   │   console = self.app.console                                                                                                             │
│    395 │   │   options = console.options                                                                                                              │
│ ❱  396 │   │   return max(                                                                                                                            │
│    397 │   │   │   Measurement.get(console, options, option.prompt).maximum                                                                           │
│    398 │   │   │   for option in self._options                                                                                                        │
│    399 │   │   )                                                                                                                                      │
│                                                                                                                                                       │
│ ╭─────────────────────────── locals ────────────────────────────╮                                                                                     │
│ │   console = <console width=153 ColorSystem.TRUECOLOR>         │                                                                                     │
│ │ container = Size(width=149, height=66)                        │                                                                                     │
│ │   options = ConsoleOptions(                                   │                                                                                     │
│ │             │   size=ConsoleDimensions(                       │                                                                                     │
│ │             │   │   width=153,                                │                                                                                     │
│ │             │   │   height=68                                 │                                                                                     │
│ │             │   ),                                            │                                                                                     │
│ │             │   legacy_windows=False,                         │                                                                                     │
│ │             │   min_width=1,                                  │                                                                                     │
│ │             │   max_width=153,                                │                                                                                     │
│ │             │   is_terminal=True,                             │                                                                                     │
│ │             │   encoding='utf-8',                             │                                                                                     │
│ │             │   max_height=68,                                │                                                                                     │
│ │             │   justify=None,                                 │                                                                                     │
│ │             │   overflow=None,                                │                                                                                     │
│ │             │   no_wrap=False,                                │                                                                                     │
│ │             │   highlight=None,                               │                                                                                     │
│ │             │   markup=None,                                  │                                                                                     │
│ │             │   height=None                                   │                                                                                     │
│ │             )                                                 │                                                                                     │
│ │      self = OptionList()                                      │                                                                                     │
│ │  viewport = Size(width=153, height=68)                        │                                                                                     │
│ ╰───────────────────────────────────────────────────────────────╯                                                                                     │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: max() iterable argument is empty

Textual Diagnostics

Versions

Name Value
Textual 1.0.0
Rich 13.9.4

Python

Name Value
Version 3.13.1
Implementation CPython
Compiler Clang 16.0.0 (clang-1600.0.26.4)
Executable /Users/davep/temp/x/.venv/bin/python

Operating System

Name Value
System Darwin
Release 24.2.0
Version Darwin Kernel Version 24.2.0: Fri Dec 6 18:51:28 PST 2024; root:xnu-11215.61.5~2/RELEASE_ARM64_T8112

Terminal

Name Value
Terminal Application ghostty (1.0.1)
TERM xterm-256color
COLORTERM truecolor
FORCE_COLOR Not set
NO_COLOR Not set

Rich Console options

Name Value
size width=153, height=68
legacy_windows False
min_width 1
max_width 153
is_terminal False
encoding utf-8
max_height 68
justify None
overflow None
no_wrap False
highlight None
markup None
height None
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 a pull request may close this issue.

1 participant