Skip to content

Fix fallback for partial list patterns - #1386

Open
AryanRG wants to merge 1 commit into
python-babel:masterfrom
AryanRG:fix-partial-list-pattern-fallbacks
Open

AryanRG wants to merge 1 commit into
python-babel:masterfrom
AryanRG:fix-partial-list-pattern-fallbacks

Conversation

@AryanRG

@AryanRG AryanRG commented Oct 14, 2026

Copy link
Copy Markdown

format_list selects the first existing style even when that style only defines some pattern parts. This raises KeyError for valid inputs such as German unit and French standard-narrow lists with three items. When 2 is missing but start and end exist, two-item lists can repeat the last item: Wolof unit-narrow formats ["A", "B"] as "A B B".

Resolve each missing part through the fallback styles, preserving the requested style's parts and collecting the result in a fresh dictionary so cached locale data is unchanged. Correct the unit-narrow chain to unit-short then standard, matching the root aliases in CLDR 45 and 48.2. The previous extra unit step could select wide-unit parts; removing it also changes Urdu two-item narrow lists from "A، B" to "A اور B" (including ur_PK and ur_IN).

Related to #781 and the whole-style fallback added in #1099 for #1098. #781's original German standard-narrow example already works on current master; this addresses the remaining partial-style failures and missing-two-item-pattern behavior.

Validation with generated CLDR 48.2 data:

  • Full suite on Python 3.12 and 3.14, each with TZ=UTC: 7,846 passed, 7 skipped, 2 xfailed (baseline: 7,831 passed).
  • List/unit tests: 49 passed. New regressions were demonstrated failing before the fix; the Santali case also failed before correcting the fallback entry.
  • Repository pre-commit hooks passed for all files.
  • External sweep of all generated locales, nine styles, and zero through five items: 60,534 cases, zero exceptions or differences from the root-alias oracle, unchanged cached patterns. All 3,488 baseline exceptions were repaired. Exactly the 100 prior successful outputs that differed from the oracle changed: 97 duplicated-item cases and the three Urdu two-item cases. All other successful outputs stayed identical.

The local timezone tests fail on the untouched base without TZ=UTC; the same timezone setting was used for the before/after full-suite comparison.

Resolve missing list-pattern parts individually without mutating locale
data. Follow the CLDR root chain for unit-narrow so narrow lists do not
fall back to unrelated wide-unit parts.

Cover partial start/end patterns, missing two-item patterns, precedence,
and locale-cache preservation with regressions.
@AryanRG
AryanRG marked this pull request as ready for review October 14, 2026 13:41

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