Skip to content

Keep star format arguments distinct from decimal conversions - #1407

Open
sunxiuguo wants to merge 2 commits into
python-babel:masterfrom
sunxiuguo:fix/star-format-compatibility-20261026
Open

sunxiuguo wants to merge 2 commits into
python-babel:masterfrom
sunxiuguo:fix/star-format-compatibility-20261026

Conversation

@sunxiuguo

Copy link
Copy Markdown

Summary

Follow up on #1402 by keeping star width/precision arguments distinct from decimal conversions during Python-format compatibility checks. The original argument-count fix remains intact.

%d, %i, and %u accept floating-point values, whereas * requires integers. On current master (9a3ef477), this incompatible translation is accepted:

args = (3.5, "word")
"%d%s" % args  # "3word"
"%*s" % args   # TypeError: * wants int
python_format(None, Message("%d%s", "%*s"))  # no error before this fix

Use a separate * category and retain only the safe direction from a star argument to a decimal conversion. Ordinary conversion compatibility and named-placeholder behavior are unchanged. No new conversion families are made compatible.

Tests

  • Against unchanged master: ten new regression cases fail (all three decimal conversions to width/precision, both positions in a double-star format, and plural catalog validation); nineteen selected controls pass.
  • After the change: checker tests and module doctests 90 passed.
  • Complete suite: 7,943 passed, 7 skipped, 2 xfailed on Linux CPython 3.12.14 with pytest 9.1.1; one existing parametrization deprecation warning.
  • CLDR 48.2 downloaded from the repository's configured Unicode URL, verified against its pinned SHA-512, and imported with the current repository script.
  • Ruff on both changed files and git diff --check pass.

Prepared with AI assistance, including independent review and actually executed synthetic tests. Hosted CI and other Python/platform combinations have not been run by this contribution; no maintainer approval is asserted.

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