Repository navigation
Conversation
format_interval() raises NotImplementedError for any skeleton whose CLDR
interval pattern defines the era ('G') or day period ('B') field, because
DateTimeFormat.extract() only understood y M d H h m a. The affected
skeletons (Gy, GyM, GyMd, GyMEd, GyMMM, GyMMMd, GyMMMEd, GyMMMM,
GyMMMMd, GyMMMMEd, GyMMMEEEEd, Bh, Bhm) are defined in interval_formats
for every locale, so format_interval(datetime(2020, 1, 1),
datetime(2021, 1, 1), 'Gy', locale='en') failed with
"Not implemented: extracting 'G' ...".
Extract those two fields, mirroring how they are rendered: the era index
from format_era() and the day period identifier from format_period().
Sweeping all locales, interval skeletons and instants (230,698 cases)
shows 20,220 NotImplementedError crashes on the base, 0 after the fix,
with no case that previously produced output changing its output.
… for it
get_timezone_location() falls back to the CLDR region 'ZZ' ('unknown
region') when the zone's territory has no name in the locale, but it then
looked that name up with [] instead of .get(), so every locale that does
not translate 'ZZ' -- 173 of the 1,121 locales -- raised KeyError: 'ZZ'
for a perfectly valid zone. get_timezone_name() reaches the same code
when no zone variant is given, so the crash surfaced through the public
name lookup too.
Leave the region out of the result in that case, which is what the
location format degenerates to when the locale cannot name the region.
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.
get_timezone_location()falls back to the CLDR regionZZ("unknown region") when the zone's territory has no name in the requested locale, but it then looked that name up with[]rather than.get(). Any locale that does not translateZZtherefore raisedKeyError: 'ZZ'for a perfectly valid zone — 173 of the 1,121 locales:get_timezone_name()callsget_timezone_location()when nozone_variantis given, so the crash also surfaced through the name lookup, which is the more common entry point.The change keeps the region name optional: when the locale cannot name the region at all, the location is returned without one, which is what the location format degenerates to. Locales that do name it are untouched (
enstill givesCanada (St. John's) Time,de_DEstill givesKanada (St. John's) (Ortszeit)), andreturn_city=Trueis unaffected.tests/test_dates.py::test_get_timezone_location_without_a_region_namecovers the fallback and the unchanged case: 2 failed withKeyError: 'ZZ'before, 33 passed in the surrounding timezone tests after, and the fulltest_dates.pyplustest_date_intervals.pyare 2400 passed / 2 xfailed.ruff checkreports no findings on either file.Prepared with AI assistance; every line was verified by running the cases above.