Repository navigation
Conversation
parse_date() only read numbers, so dates in formats that spell out the
month, which is the default medium format of en_US and most other
locales, raised an IndexError, e.g. parse_date('Nov 24, 2026',
locale='en_US').
Look for the locale's month names, then English ones, when the pattern
has a textual month field. Names must be separate words unless the
pattern attaches letters to the month (Hebrew, Basque, ...), and a match
inside a day name is skipped (in Welsh "Mawrth" is Tuesday and March).
Input with too few numbers now raises ParseError instead of IndexError.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
parse_date()only reads numbers, so it can't parse dates whose format spells the month out. That includes the defaultmediumformat ofen_USand most other locales, so Babel can't parse its own output:This resolves the FIXME in
parse_date(). When the pattern has a textual month field (MMM/MMMM/LLL/LLLL), it looks for the locale's month names (format and stand-alone, wide and abbreviated), then the English ones, and uses the remaining numbers for the year and day. Numeric patterns go through the same code as before.Some locale details I had to handle:
d בMMM y(he) orMMMM'ren'(eu).Input with too few numbers (e.g. "Nov 2026") now raises
ParseErrorinstead ofIndexError. #1282 fixed theValueErrorcase. #1365 was closed as already done in #1282, but theIndexErrorstill happens on master.To check this, I formatted 7 dates in
short/medium/long/fullfor every locale in CLDR and parsed them back:None of them parse to a wrong date, before or after. The remaining ParseErrors come from two locales:
mgo, whose day names contain a digit ("Aneg 2"), andnnh. Parsing a month-name date takes about 35 µs, because the regexes are cached per locale.Tests: added cases for the locales above, a format/parse round trip for a few locales in all four formats, and the
ParseErrorcases. The full suite passes on Python 3.14, andruff checkis clean.Prepared with AI assistance (Claude Code).
🤖 Generated with Claude Code