Skip to content

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

Description

@pramodavansaber

Description

tabulate(...) raises TypeError when rowalign (or maxheadercolwidths) is passed as a tuple instead of a list, even though every other sequence-valued parameter (headers, colalign, floatfmt, maxcolwidths, ...) accepts a tuple.

Reproduction

from tabulate import tabulate

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

tabulate([[1, 2], [3, 4]], rowalign=["top", "bottom"])   # works

Root cause

The internal sequence-padding helper does original + [default] * (num_desired - len(original)). When original is a tuple this is tuple + list, which raises (and it raises even when no padding is needed, since tuple + [] still fails). Coercing with list(original) first fixes it and matches how the other parameters behave.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions