-
Notifications
You must be signed in to change notification settings - Fork 460
Fix: Handle None value for locale in format_currency #1158
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -774,6 +774,8 @@ def format_currency( | |||||
| locale=locale, currency_digits=currency_digits, | ||||||
| decimal_quantization=decimal_quantization, group_separator=group_separator, | ||||||
| numbering_system=numbering_system) | ||||||
| if locale is None: | ||||||
| locale = default_locale() | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Though I'm not sure if it makes sense to just fix this one function. A lot of the other from babel.numbers import format_compact_currency
format_compact_currency('12', 'EUR', locale=None)I think if we're gonna fix this, we should fix all of them at the same time, otherwise we're gonna have functions with the same type annotation behaving differently which could lead to confusion. |
||||||
| locale = Locale.parse(locale) | ||||||
| if format: | ||||||
| pattern = parse_pattern(format) | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It bugs me that
default_locale()determines the locale as a string, parses it to aLocale, and converts it to its string identifier. Then immediately after, it's parsed back to aLocale.But I can't think of a good way around this, other than a breaking change in
default_locale().