Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/48.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Converted non-string table cells to strings during rendering.
4 changes: 4 additions & 0 deletions src/cleo/ui/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,10 @@ def _build_table_rows(self, rows: Rows) -> Iterator[Row | TableSeparator]:

# Remove any new line breaks and replace it with a new line
for column, cell in enumerate(rows[row_key]):
if not isinstance(cell, str):
cell = str(cell)
rows[row_key][column] = cell

colspan = cell.colspan if isinstance(cell, TableCell) else 1

if column in self._column_max_widths and self._column_max_widths[
Expand Down
19 changes: 19 additions & 0 deletions tests/ui/test_table.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import cast

import pytest

Expand Down Expand Up @@ -428,6 +429,24 @@ def test_render(
assert io.fetch_output() == expected


def test_render_non_string_cells(io: BufferedIO) -> None:
table = Table(io)
table.set_headers(["Value", "Detail"])
table.set_rows(cast("Rows", [[None, 12], [False, "ready"]]))

table.render()

expected = """\
+-------+--------+
| Value | Detail |
+-------+--------+
| None | 12 |
| False | ready |
+-------+--------+
"""
assert io.fetch_output() == expected


def test_column_style(io: BufferedIO) -> None:
table = Table(io)
table.set_headers(["ISBN", "Title", "Author", "Price"])
Expand Down
Loading