Repository navigation
Fix TypeError when rowalign is passed as tuple (#440) - #468
Open
thejedi433 wants to merge 1 commit into
Open
thejedi433 wants to merge 1 commit into
thejedi433 wants to merge 1 commit into
Conversation
The _expand_iterable helper function attempted to concatenate a tuple with a list using the + operator, which raises TypeError in Python. This caused tabulate() to fail when users passed alignment parameters (rowalign, colalign, numalign, stralign) as tuples instead of lists. Fix by converting the iterable to a list before concatenation. Also exclude bytes from iterable check for consistency. Fixes astanin#440
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Calling
tabulate()withrowalign(or any alignment parameter) as a tuple raisesTypeError:This was reported in #440.
Root cause
_expand_iterable(line 2482 intabulate/__init__.py) usesoriginal + [default] * N. Whenoriginalis a tuple,tuple + listraisesTypeError.Fix
Two changes in
_expand_iterable:originalto alistbefore concatenation — handles tuple, set, generator, and any other iterable uniformly.bytesto the exclusion list alongsidestrfor consistency (abytesvalue shouldn't be expanded element-wise either).This affects
rowalign,colalign,numalign,stralign,numparse,maxcolwidths, andmaxheadercolwidths— all of which flow through_expand_iterable.Tests
Added
test/test_rowalign_tuple.pywith 8 tests covering:rowalignno longer raisesTypeErrorcolalign,numalign,stralign) work with tuplesAll 314 existing tests still pass (60 skipped due to optional dependencies).
Scope
Minimal — two lines changed in
_expand_iterable, no other behavior affected. No documentation or API changes.