DataTable column added with the default `None` is at least four cells wide, though its cells are empty
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Read the DataTable methods _get_row_renderables and _update_column_widths, along with the update_cell(..., update_width=True) path mentioned in the issue. Check existing DataTable tests for column sizing and add coverage for None cells; done means their measured width matches the empty rendering and the reported table width is corrected.
Written by the indexing model from the issue text.
Description
Hi! I hit this while writing generated tests against Textual's widgets. add_column on a table that already has rows fills those rows with default, which is None. The cells are drawn empty, but the column is sized as if they contained the text None.
import asyncio
from textual.app import App, ComposeResult
from textual.widgets import DataTable
class NewColumnApp(App):
def compose(self) -> ComposeResult:
yield DataTable()
def on_mount(self) -> None:
table = self.query_one(DataTable)
table.add_column("A")
table.add_row("1")
table.add_column("B") # existing rows get the default, None
async def main():
async with NewColumnApp().run_test() as pilot:
await pilot.pause()
table = pilot.app.query_one(DataTable)
for column in table.ordered_columns:
print(f"column {column.label.plain}: content_width={column.content_width}")
print("cell B:", repr(table.get_cell_at((0, 1))))
print("table width:", table.virtual_size.width)
asyncio.run(main())
Output on Textual 8.2.7 (and the same on main at 5e5b7ef):
column A: content_width=1
column B: content_width=4
cell B: None
table width: 9
I'd expect column B to be 1 wide (its label), and the table 6 wide.
_get_row_renderables draws a None cell as empty text, but _update_column_widths measures default_cell_formatter(None), which is str(None). update_cell(..., None, update_width=True) goes through the same path.
I'd suggest measuring None cells as empty in _update_column_widths, to match how they're drawn. I'm happy to send a PR.
- Dominant language
- Python
- Stars
- 37.7k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Textualize/textual
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Textualize/textual#6790 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
Textualize/textual#6789 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Textualize/textual#6787 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Textualize/textual#6782 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Textualize/textual#6778 · 1 comment ·
All issues in Textualize/textual
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
GoogleCloudPlatform/professional-services-data-validator#1899 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
mohanraj00/entelos#200 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
-
sweep
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
bketelsen/truenas-mcp#77 ·
Maintainers usually reply within 1 day
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskOpen
Difficulty 1/5 Under an hour Newbie friendliness 86/100
sandbox-quantum/switch#2163 ·
Maintainers usually reply within 1 day