Skip to content

Ignore quoted percent and per-mille scaling symbols - #1370

Draft
vhinayindia wants to merge 1 commit into
python-babel:masterfrom
vhinayindia:fix/quoted-number-scale
Draft

vhinayindia wants to merge 1 commit into
python-babel:masterfrom
vhinayindia:fix/quoted-number-scale

Conversation

@vhinayindia

Copy link
Copy Markdown

NumberPattern.compute_scale() counts % and ‰ inside quoted affixes, so a
literal symbol can silently multiply the value being formatted:

from decimal import Decimal
from babel.numbers import format_decimal

format_decimal(Decimal('12.3'), "0.0'%'", locale='en_US')
# Before: '1230.0%'
# After:  '12.3%'

The LDML special-pattern-character rules
specify that quoting removes a character's special meaning. Remove complete
quoted spans from each affix before detecting scaling symbols, retaining the
existing percent precedence and behavior for unmatched apostrophes.

The regressions cover decimal and percent formatting, prefixes and suffixes,
positive and negative values, explicit negative subpatterns, mixed literal and
active symbols, scientific/significant-digit patterns, and apostrophe handling.
The separate existing rendering issue that drops doubled apostrophes inside a
quoted span is unchanged; those cases are checked at the scale level here.

Validation on Python 3.12.14 with the project's checksum-verified CLDR 48.2 data
and the tzdata package:

  • Final new cases on unchanged master: 35 failed, 24 passed.
  • Patched tests/test_numbers.py: 190 passed.
  • Full patched suite: 7,890 passed, 7 skipped, 2 xfailed.
  • All applicable pinned pre-commit hooks passed.
  • Source distribution and wheel built successfully.

Both baseline and patched full-suite runs used TZ=UTC to avoid the existing
non-UTC get_timezone_name(None) test failures. The original suite passed
7,831 tests under the same conditions. Both runs retained the existing pytest
deprecation warning about generator-based parametrization in the TOML tests.

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