Skip to content

Clarify intcomma errors for negative precision - #467

Open
ShahadatTest wants to merge 1 commit into
python-humanize:mainfrom
ShahadatTest:intcomma-negative-precision
Open

ShahadatTest wants to merge 1 commit into
python-humanize:mainfrom
ShahadatTest:intcomma-negative-precision

Conversation

@ShahadatTest

Copy link
Copy Markdown

Fixes #466.

Passing a negative ndigits to intcomma() currently exposes Python's ValueError: Format specifier missing precision. Raise ValueError: ndigits must be non-negative instead, and document the supported precision and exception.

The validation stays after the existing value conversion, preserving how non-numeric and non-finite inputs are handled. Add six regression cases covering -1 and -10 for integer, float, and numeric-string values. All six fail against the original source because the error message is different.

Validation on Windows, CPython 3.14.6:

  • pytest --benchmark-disable --doctest-modules --color=no -q: 860 passed, 2 skipped. The skipped cases update translations and require GNU gettext tools unavailable on this machine. Existing translation catalogs were compiled locally with polib for the remaining localization tests; benchmark timing was disabled.
  • pytest tests/test_number.py -q --color=no: 247 passed.
  • prek run --files src/humanize/number.py tests/test_number.py: passed.
  • mypy .: passed, 14 source files.
  • mkdocs build --strict: passed.

AI disclosure: the implementation, tests, and this description were prepared with OpenAI Codex.

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.

intcomma(num, ndigits=-1) ValueError: Format specifier missing precision

1 participant