Skip to content

format_decimal: reject unsupported numbering systems with group_separator=False - #1369

Open
glaziermag wants to merge 1 commit into
python-babel:masterfrom
glaziermag:fix-decimal-numbering-e2a17919-01a111eb
Open

glaziermag wants to merge 1 commit into
python-babel:masterfrom
glaziermag:fix-decimal-numbering-e2a17919-01a111eb

Conversation

@glaziermag

Copy link
Copy Markdown

With group_separator=False, format_decimal silently accepts an unsupported numbering system when the formatted fractional part is zero. Grouped output and output with a nonzero fractional part already raise UnsupportedNumberingSystemError, because those rendering branches fetch number symbols and validate the system.

Validate the numbering system immediately after parsing the locale, before formatting. The regression test covers zero, an integer, and a value rounded to an integer, with grouping enabled and disabled.

Minimal reproduction on unmodified master at e2a17919f0eb988bfea2883b00793ca4d5d37c4f:

from babel.numbers import format_decimal

format_decimal(1, locale="en_US", group_separator=False, numbering_system="unknown")

Actual: '1'. Expected: UnsupportedNumberingSystemError, as documented in the project's format_decimal API contract.

Validation on Python 3.14.4 with the project's CLDR 48.2 data:

  • Regression test before the fix: 3 failed, 3 passed; after the fix: all 6 passed.
  • Number tests: 137 passed.
  • Full suite, python -X utf8 -m pytest -q: 7,837 passed, 7 skipped, 2 xfailed.
  • git diff --check: passed.

Prepared and tested with OpenAI Codex.

Reject unsupported systems even when ungrouped integer output needs no locale number symbols.

Assisted-by: OpenAI Codex

This branch has not been deployed

No deployments
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.

1 participant