Accept C and POSIX in Locale.parse - #1340
Conversation
default_locale already maps those to en_US_POSIX. parse() did not, so a C locale from the environment raised UnknownLocaleError.
|
|
||
| # C/POSIX is not a CLDR language. Same mapping default_locale uses. | ||
| posix_stem = identifier.split(".")[0].split("@")[0] | ||
| posix_stem = posix_stem.replace("-", "_") |
There was a problem hiding this comment.
Why is this replace necessary? "C" and "POSIX" don't include dashes or underscores.
| raise TypeError(f"Unexpected value for identifier: {identifier!r}") | ||
|
|
||
| # C/POSIX is not a CLDR language. Same mapping default_locale uses. | ||
| posix_stem = identifier.split(".")[0].split("@")[0] |
There was a problem hiding this comment.
What's the @ splitting for? The test case doesn't seem to exercise it, and in any case a @ modifier would be in the postfix already split out by .split(".").
Additionally, please use .partition(".") in cases like this for performance.
C and POSIX never include a dash or @ modifier on the language stem, so the extra replace and split were noise.
|
Dropped the dash replace and the |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1340 +/- ##
=======================================
Coverage 93.37% 93.37%
=======================================
Files 27 27
Lines 4919 4922 +3
=======================================
+ Hits 4593 4596 +3
Misses 326 326
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:
|
Fixes #1236.
default_locale()mapsC,POSIX, andC.UTF-8toen_US_POSIX.Locale.parse()did not, soLocale.parse("C")raisedUnknownLocaleError: unknown locale 'c'. That is the frame in the report.parse()now applies the same mapping (case-insensitive, optional encoding suffix) beforeparse_locale.en_US_POSIXwith a POSIX variant is unchanged.