Skip to content

fix: accept tuples (and any sequence) in _expand_iterable, not just lists - #437

Open
koteshyelamati wants to merge 1 commit into
astanin:masterfrom
koteshyelamati:patch-1
Open

fix: accept tuples (and any sequence) in _expand_iterable, not just lists#437
koteshyelamati wants to merge 1 commit into
astanin:masterfrom
koteshyelamati:patch-1

Conversation

@koteshyelamati

Copy link
Copy Markdown

Fixes#434

Problem

tabulate() raises TypeError when sequence-valued parameters like rowalign or maxheadercolwidths are passed as tuples instead of lists:

fromtabulateimporttabulatetabulate([[1, 2], [3, 4]], rowalign=("top", "bottom"))
# TypeError: can only concatenate tuple (not "list") to tupletabulate([[1, 2], [3, 4]], rowalign=["top", "bottom"]) # works

All other sequence-valued parameters (colalign, floatfmt, maxcolwidths, etc.) accept tuples, so this is an inconsistency.

Root cause

_expand_iterable does original + [default] * n. When original is a tuple, tuple + list raises TypeError.

Fix

Coerce original to a list before concatenation:

# beforereturnoriginal+ [default] * (num_desired-len(original))
# afterreturnlist(original) + [default] * (num_desired-len(original))

Sign up for freeto 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

@koteshyelamati