Skip to content

parse_decimal: reject underscore grouping with strict=True - #1355

Open
glaziermag wants to merge 1 commit into
python-babel:masterfrom
glaziermag:fix/strict-decimal-underscores
Open

glaziermag wants to merge 1 commit into
python-babel:masterfrom
glaziermag:fix/strict-decimal-underscores

Conversation

@glaziermag

Copy link
Copy Markdown

parse_decimal('1_000', locale='en_US', strict=True) currently returns Decimal('1000'), although strict mode promises to reject irregularly formatted numbers. The strict-validation branch only runs when the locale's grouping separator is present, so Decimal's underscore syntax bypasses it.

Run against the current default branch:

from babel.numbers import parse_decimal

parse_decimal('1_000', locale='en_US', strict=True)
# Actual: Decimal('1000')
# Expected: NumberFormatError

The documented strict-mode guarantee requires an exception for irregular formatting.

This change sends underscore-containing input through the existing strict validation. Regression tests cover en_US and de, including acceptance of valid grouped and ungrouped input and preservation of permissive parsing.

Validation: clean baseline reproduced twice; full local suite on Python 3.12: 7,833 passed, 7 skipped, 2 xfailed. Ruff and git diff --check pass. The new regression cases also pass after the final lint adjustment.

Prepared with AI assistance.

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