Skip to content

Fix ordinal day parsing in locales without suffixes - #1091

Open
CyberKun wants to merge 1 commit into
python-pendulum:masterfrom
CyberKun:fix/ordinal-parser-errors
Open

CyberKun wants to merge 1 commit into
python-pendulum:masterfrom
CyberKun:fix/ordinal-parser-errors

Conversation

@CyberKun

Copy link
Copy Markdown

from_format() crashes with AttributeError for Do in locales without custom ordinal suffixes, even when parsing the output of format(). For example, a German YYYY-MM-Do string cannot round-trip.

Use a bare numeric pattern when the locale has no ordinal suffix mapping, and escape existing suffixes as literal text. Also reject localized tokens mapped to None with the existing ValueError("Unsupported token: ...") diagnostic instead of looking up a nonexistent translation.

Partially addresses #1074: this fixes Do and the unsupported-token errors. Adding parsing support for Mo, Qo, and DDDo remains separate work.

Validation:

  • 62 parametrized regression cases passed (9 locales across 6 days, plus 8 unsupported tokens). Before the fix, 50 failed and 12 passed.

  • Existing formatting tests: 22 passed.

  • Ruff 0.14.11 lint and format checks passed for both changed files.

  • Tests ran on Python 3.14 with PYTHONPATH=src and PENDULUM_EXTENSIONS=0. The full suite was not run: Windows Application Control blocks the native time-machine dependency used by the time-travel tests.

  • Added tests for changed code.

  • Updated documentation for changed code (no new supported tokens or public API).

Signed-off-by: Aditya <adityasbakawat@gmail.com>

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