Skip to content

Fix compatibility checks for scientific float placeholders - #1446

Open
liugedragon wants to merge 1 commit into
python-babel:masterfrom
liugedragon:fix/scientific-format-compatibility
Open

liugedragon wants to merge 1 commit into
python-babel:masterfrom
liugedragon:fix/scientific-format-compatibility

Conversation

@liugedragon

Copy link
Copy Markdown

python_format() rejects valid translations such as %e → %E and %f → %e. The placeholder parser recognizes both scientific conversions, but the float compatibility group only contains f/F/g/G.

Include e/E in that group, matching Python's floating-point percent conversions. Integer, hexadecimal and string conversion groups remain unchanged.

Tests cover all six float conversions in positional and named messages, non-float rejection controls, and a plural catalog. Each positive case also formats the same actual float with both strings. Before the fix, 37 of the 85 new cases fail; after it, all pass.

Validation on Windows / Python 3.13.4 after importing the repository's CLDR 49 data:

  • Full suite: 8,292 passed, 10 skipped, 2 xfailed.
  • tests/messages: 555 passed.
  • Ruff check on both changed files, using the pinned 0.14.10 version: passed.

@akx akx added the AI Assisted label Nov 9, 2026

@chrikrah chrikrah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liugedragon %e and %E join the float group, nothing else moves. Fine to merge from my side.

# git archive a3c5b31 (base a18709c), Python 3.12, CLDR imported, babel.__file__ from the export
$ python -m pytest -q tests
6922 passed, 1219 skipped, 1 xfailed
# python_format(None, Message("v %.2e", "w %.3f")) at a18709c
TranslationError: incompatible format for placeholder 1: 'e' and 'f' are not compatible
# t.po: one python-format entry, msgid "v %.2e", msgstr "w %.3f"
$ msgfmt --version | head -1
msgfmt (GNU gettext-tools) 1.0
$ msgfmt --check-format -o /dev/null t.po; echo exit=$?
exit=0

GNU msgfmt already accepts %e against %f.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants