Skip to content

Honor disable_numparse on the maxcolwidths wrap path (#428)#431

Open
assinscreedFC wants to merge 1 commit into
astanin:masterfrom
assinscreedFC:fix/428-disable-numparse-maxcolwidths
Open

Honor disable_numparse on the maxcolwidths wrap path (#428)#431
assinscreedFC wants to merge 1 commit into
astanin:masterfrom
assinscreedFC:fix/428-disable-numparse-maxcolwidths

Conversation

@assinscreedFC
Copy link
Copy Markdown

Summary

Fixes #428 — a regression of #305 (originally fixed by #362), present on master and in v0.10.0.

When disable_numparse=True is combined with maxcolwidths, a cell that looks number-ish but cannot be parsed (e.g. '80,443', a comma-separated port list) crashes:

from tabulate import tabulate
tabulate(
    [['ports', 'str', 'comma-separated port list', '80,443']],
    ['name', 'type', 'desc', 'default'],
    tablefmt='grid', disable_numparse=True, maxcolwidths=40,
)
# ValueError: invalid literal for int() with base 10: '80,443'

The same input works without maxcolwidths: disable_numparse is honored on the non-wrap path but ignored on the wrap path.

Root cause

In _wrap_text_to_colwidths, the per-cell numparse flag was passed positionally to _type():

str(_type(cell, numparse)(cell))

_type's signature is _type(string, has_invisible=True, numparse=True), so numparse was actually filling has_invisible, and _type always ran with its default numparse=True. The unparseable cell was then cast to int.

Fix

Pass numparse as a keyword argument:

str(_type(cell, numparse=numparse)(cell))

One-character-class change; has_invisible keeps its default.

Test plan

  • Added test_disable_numparse_honored_with_maxcolwidths in test/test_regression.py.
  • pytest test/ — 366 passed, 1 skipped.
  • ruff check / ruff format --check — clean.
  • Verified real numbers are still parsed/aligned by default (no behaviour change when disable_numparse is not set).

In _wrap_text_to_colwidths, the per-cell numparse flag was passed
positionally to _type() as the has_invisible argument:

    _type(cell, numparse)

so _type() always used its default numparse=True. A number-ish but
unparseable cell (e.g. '80,443') was then cast to int and crashed with
ValueError, but only when maxcolwidths triggered the wrap path -- the
non-wrap path honored disable_numparse correctly.

Pass numparse as a keyword argument. This restores the fix from astanin#362
(regression of astanin#305 / astanin#428).

Fixes astanin#428
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.

Regression of #305 in v0.10.0: disable_numparse=True is ignored when maxcolwidths is set

1 participant