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
2 changes: 1 addition & 1 deletion tabulate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2488,7 +2488,7 @@ def _expand_iterable(original, num_desired, default):
length `num_desired` completely populated with `default will be returned
"""
if isinstance(original, Iterable) and not isinstance(original, str):
return original + [default] * (num_desired - len(original))
return list(original) + [default] * (num_desired - len(original))
else:
return [default] * num_desired

Expand Down
5 changes: 5 additions & 0 deletions test/test_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,8 @@ def test__reinsert_separating_lines():
expected = rows_to_pipe_table_str(with_rows)

assert_equal(expected, rows_to_pipe_table_str(sans_rows))

def test_expand_iterable_accepts_tuple():
"Internal: _expand_iterable pads tuples the same way as lists (issue #434)"
assert_equal(["top", "bottom"], T._expand_iterable(("top", "bottom"), 2, "top"))
assert_equal(["left", "left", "left"], T._expand_iterable(("left",), 3, "left"))
6 changes: 6 additions & 0 deletions test/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,3 +598,9 @@ def test_github_escape_pipe_character():
result = tabulate([["foo|bar"]], headers=("spam|eggs",), tablefmt="github")
expected = "| spam\\|eggs |\n|:------------|\n| foo\\|bar |"
assert_equal(expected, result)

def test_rowalign_tuple():
"Regression: rowalign (and other sequence kwargs) accept tuples (issue #434)"
result = tabulate([[1, 2], [3, 4]], rowalign=("top", "bottom"))
expected = tabulate([[1, 2], [3, 4]], rowalign=["top", "bottom"])
assert_equal(expected, result)