Repository navigation
Conversation
akx
left a comment
There was a problem hiding this comment.
What are the format_interval changes in this PR?
… 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' -- 347 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.
8a5ffe9 to
12c84da
Compare
|
They are out of scope and I have removed them. They came from an earlier commit on this branch that taught Two corrections while I am here:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1405 +/- ##
==========================================
+ Coverage 93.37% 93.59% +0.22%
==========================================
Files 27 27
Lines 4922 4953 +31
==========================================
+ Hits 4596 4636 +40
+ Misses 326 317 -9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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 — 183 of the 1,121 locale identifiers:python >>> from babel.dates import get_timezone, get_timezone_location, get_timezone_name >>> tz = get_timezone('Europe/Paris') >>> get_timezone_location(tz, locale='aa') KeyError: 'ZZ' >>> get_timezone_name(tz, locale='aa') # reaches the same code with no zone variant KeyError: 'ZZ'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.