python-tabulate icon indicating copy to clipboard operation
python-tabulate copied to clipboard

type error when using maxcolwidths with colored strings

Open Camyll opened this issue 11 months ago • 0 comments

Issue: colored string type throwing an error in casted_cell assignment because _type method not equipped to handle it. Can we either:

  • add a type check to see if cell is already a str before putting it through 'casted_cell'? This could avoid the need for edge case checks but I may be misunderstanding why this method was necessary to begin with.
  • add colored string type to _type method. From the method details it seems that it should be equipped to handle input '\x1b[43m\x1b[30m3\x1b[0m' but it throws an error
input value for 'cell': "3" (colored string)
Error: 
  File "/data/sandcastle/boxes/fbsource/buck-out/v2/gen/fbcode/e104f4d0e1969b09/pytorchrelengoncall/__syncdiag__/syncdiag#link-tree/tabulate/__init__.py", line 1516, in _wrap_text_to_colwidths
    str(cell) if _isnumber(cell) else _type(cell, numparse)(cell)
ValueError: invalid literal for int() with base 10: '\x1b[43m\x1b[30m3\x1b[0m'

Camyll avatar Feb 12 '25 23:02 Camyll