Skip to content

Improve handling for locale=None#1164

Merged
akx merged 5 commits intomasterfrom
locale-none
Jan 9, 2025
Merged

Improve handling for locale=None#1164
akx merged 5 commits intomasterfrom
locale-none

Conversation

@akx
Copy link
Member

@akx akx commented Jan 8, 2025

This PR improves the handling of None as a locale= argument.

Namely:

  • The error message Locale.parse() raises for falsy arguments is more descriptive.
  • Explicitly passing in None for a public API means "use the default", not "crash on me".
    • ⚠️ 👉 This could change the behavior of user code that is not very well defined to begin with, that would have expected an exception to be raised for a None locale, but I hope that sort of code isn't very popular.
    • If a default is not available (e.g. on Windows, or when environment variables are fubar'd), we'll still crash, but with a nicer error message than ever before.

Fixes #1156.
Closes #1158 (supersedes it).

@akx akx requested a review from tomasr8 January 8, 2025 14:40
@codecov
Copy link

codecov bot commented Jan 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.31%. Comparing base (6bbdc0e) to head (9327e5f).
Report is 6 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1164   +/-   ##
=======================================
  Coverage   91.31%   91.31%           
=======================================
  Files          27       27           
  Lines        4638     4654   +16     
=======================================
+ Hits         4235     4250   +15     
- Misses        403      404    +1     
Flag Coverage Δ
macos-14-3.10 90.33% <100.00%> (+0.01%) ⬆️
macos-14-3.11 90.26% <100.00%> (+0.01%) ⬆️
macos-14-3.12 90.48% <100.00%> (+0.01%) ⬆️
macos-14-3.13 90.48% <100.00%> (+0.01%) ⬆️
macos-14-3.8 90.19% <100.00%> (+0.01%) ⬆️
macos-14-3.9 90.26% <100.00%> (+0.01%) ⬆️
macos-14-pypy3.10 90.33% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.10 90.35% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.11 90.28% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.12 90.50% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.13 90.50% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.8 90.21% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.9 90.28% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-pypy3.10 90.35% <100.00%> (+0.01%) ⬆️
windows-2022-3.10 90.36% <100.00%> (+0.01%) ⬆️
windows-2022-3.11 90.29% <100.00%> (+0.01%) ⬆️
windows-2022-3.12 90.51% <100.00%> (+0.01%) ⬆️
windows-2022-3.13 90.51% <100.00%> (+0.01%) ⬆️
windows-2022-3.8 90.33% <100.00%> (+0.01%) ⬆️
windows-2022-3.9 90.29% <100.00%> (+0.01%) ⬆️
windows-2022-pypy3.10 90.36% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@akx akx marked this pull request as ready for review January 8, 2025 16:10
@tomasr8
Copy link
Member

tomasr8 commented Jan 8, 2025

I'll try to take a look later today :)

Copy link
Member

@tomasr8 tomasr8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I left you some comments :)
Hopefully I didn't miss anything with so many similar changes 😅

@akx akx requested a review from tomasr8 January 9, 2025 08:34
Copy link
Member

@tomasr8 tomasr8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one thing:

@akx akx merged commit 1174cd1 into master Jan 9, 2025
@akx akx deleted the locale-none branch January 9, 2025 12:41
@akx akx added this to the Babel 2.17 milestone Jan 14, 2025
radermacher-iits pushed a commit to kubara-io/kubara that referenced this pull request Feb 19, 2026
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [babel](https://babel.pocoo.org/) ([source](https://github.com/python-babel/babel)) | packages | minor | `==2.17.0` → `==2.18.0` |

---

### Release Notes

<details>
<summary>python-babel/babel (babel)</summary>

### [`v2.18.0`](https://github.com/python-babel/babel/blob/HEAD/CHANGES.rst#Version-2180)

[Compare Source](python-babel/babel@v2.17.0...v2.18.0)

Happy 2026! This release is, coincidentally, also being made from FOSDEM.

We will aspire for a slightly less glacial release cadence in this year;
there are interesting features in the pipeline.

Features

```

* Core: Add `babel.core.get_cldr_version()` by @&#8203;akx in :gh:`1242`
* Core: Use CLDR 47 by @&#8203;tomasr8 in :gh:`1210`
* Core: Use canonical IANA zone names in zone_territories by @&#8203;akx in :gh:`1220`
* Messages: Improve extract performance via ignoring directories early during os.walk by @&#8203;akx in :gh:`968`
* Messages: Merge in per-format keywords and auto_comments by @&#8203;akx in :gh:`1243`
* Messages: Update keywords for extraction of dpgettext and dnpgettext by @&#8203;mardiros in :gh:`1235`
* Messages: Validate all plurals in Python format checker by @&#8203;tomasr8 in :gh:`1188`
* Time: Use standard library `timezone` instead of `FixedOffsetTimezone` by @&#8203;akx in :gh:`1203`

Bugfixes
```

- Core: Fix formatting for "Empty locale identifier" exception added in [#&#8203;1164](python-babel/babel#1164) by [@&#8203;akx](https://github.com/akx) in :gh:`1184`
- Core: Improve handling of no-inheritance-marker in timezone data by [@&#8203;akx](https://github.com/akx) in :gh:`1194`
- Core: Make the number pattern regular expression more efficient by [@&#8203;akx](https://github.com/akx) in :gh:`1213`
- Messages: Keep translator comments next to the translation function call by [@&#8203;akx](https://github.com/akx) in :gh:`1196`
- Numbers: Fix KeyError that occurred when formatting compact currencies of exactly one thousand in several locales  by [@&#8203;bartbroere](https://github.com/bartbroere) in :gh:`1246`

Other improvements

```

* Core: Avoid unnecessary uses of `map()` by @&#8203;akx in :gh:`1180`
* Messages: Have init-catalog create directories too by @&#8203;akx in :gh:`1244`
* Messages: Optimizations for read_po by @&#8203;akx in :gh:`1200`
* Messages: Use pathlib.Path() in catalog frontend; improve test coverage by @&#8203;akx in :gh:`1204`

Infrastructure and documentation
```

- CI: Renovate CI & lint tools by [@&#8203;akx](https://github.com/akx) in :gh:`1228`
- CI: Tighten up CI with Zizmor by [@&#8203;akx](https://github.com/akx) in :gh:`1230`
- CI: make job permissions explicit by [@&#8203;akx](https://github.com/akx) in :gh:`1227`
- Docs: Add SECURITY.md by [@&#8203;akx](https://github.com/akx) in :gh:`1229`
- Docs: Remove u string prefix from docs by [@&#8203;verhovsky](https://github.com/verhovsky) in :gh:`1174`
- Docs: Update dates.rst with current unicode.org tr35 link by [@&#8203;clach04](https://github.com/clach04) in :gh:`1189`
- General: Add some PyPI classifiers by [@&#8203;tomasr8](https://github.com/tomasr8) in :gh:`1186`
- General: Apply reformatting by hand and with Ruff by [@&#8203;akx](https://github.com/akx) in :gh:`1202`
- General: Test on and declare support for Python 3.14 by [@&#8203;akx](https://github.com/akx) in :gh:`1233`
- Tests: Convert Unittest testcases with setup/teardown to fixtures by [@&#8203;akx](https://github.com/akx) in :gh:`1240`
- Tests: Mark PyPy CI flake as xfail by [@&#8203;akx](https://github.com/akx) in :gh:`1197`
- Tests: Move pytest config to `pyproject.toml` by [@&#8203;tomasr8](https://github.com/tomasr8) in :gh:`1187`
- Tests: Unwrap most `unittest` test cases to bare functions by [@&#8203;akx](https://github.com/akx) in :gh:`1241`

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4zLjYiLCJ1cGRhdGVkSW5WZXIiOiI0My4zLjYiLCJ0YXJnZXRCcmFuY2giOiJtYXN0ZXIiLCJsYWJlbHMiOltdfQ==-->

Reviewed-on: https://kubara.git.onstackit.cloud/STACKIT/kubara/pulls/275
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.

locale parameter cannot be None

2 participants