Skip to content

Accept tuples for rowalign and other sequence arguments#436

Open
uttam12331 wants to merge 1 commit into
astanin:masterfrom
uttam12331:fix/434-rowalign-tuple
Open

Accept tuples for rowalign and other sequence arguments#436
uttam12331 wants to merge 1 commit into
astanin:masterfrom
uttam12331:fix/434-rowalign-tuple

Conversation

@uttam12331

Copy link
Copy Markdown

Summary

Closes #434.

tabulate(..., rowalign=('top', 'bottom')) raised:

TypeError: can only concatenate tuple (not "list") to tuple

_expand_iterable() concatenated its padding list directly onto the original iterable (original + [default] * n). When original is a tuple — as a user can reasonably pass for rowalign (and maxcolwidths/maxheadercolwidths) — tuple + list fails, even when no padding is needed.

Fix

Coerce original to a list before concatenating, so any non-list sequence behaves the same as a list:

original = list(original)
return original + [default] * (num_desired - len(original))

Tests

Added test_rowalign_tuple to test/test_regression.py asserting the tuple form produces the same output as the list form.

Verified locally: full suite pytest test/366 passed, 1 skipped.

tabulate(..., rowalign=('top', 'bottom')) raised
'TypeError: can only concatenate tuple (not "list") to tuple' because
_expand_iterable() concatenated the padding list directly onto the original
iterable. Coerce the iterable to a list first, so non-list sequences (e.g. a
tuple passed as rowalign or maxcolwidths) work the same as lists.

Closes astanin#434
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 this pull request may close these issues.

tabulate() raises TypeError when rowalign is passed as a tuple instead of a list

1 participant