Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve handling for locale=None #1164

Merged
merged 5 commits into from
Jan 9, 2025
Merged

Improve handling for locale=None #1164

merged 5 commits into from
Jan 9, 2025

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
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 😅

babel/core.py Show resolved Hide resolved
babel/numbers.py Outdated Show resolved Hide resolved
babel/numbers.py Outdated Show resolved Hide resolved
babel/lists.py Outdated Show resolved Hide resolved
@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:

babel/core.py Show resolved Hide resolved
@akx akx merged commit 1174cd1 into master Jan 9, 2025
26 checks passed
@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
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