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

locale parameter cannot be None #1156

Closed
injust opened this issue Nov 26, 2024 · 3 comments · Fixed by #1164
Closed

locale parameter cannot be None #1156

injust opened this issue Nov 26, 2024 · 3 comments · Fixed by #1164
Milestone

Comments

@injust
Copy link

injust commented Nov 26, 2024

Overview Description

The type annotations for the locale parameter (e.g. in babel.numbers.format_currency()) suggest that the value can be None, but this causes a TypeError in Locale.parse().

Steps to Reproduce

babel.numbers.format_currency(0, "USD", locale=None)

Actual Results

Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    babel.numbers.format_currency(0, "USD", locale=None)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.13/site-packages/babel/numbers.py", line 777, in format_currency
    locale = Locale.parse(locale)
  File ".venv/lib/python3.13/site-packages/babel/core.py", line 332, in parse
    raise TypeError(f"Unexpected value for identifier: {identifier!r}")
TypeError: Unexpected value for identifier: None

Expected Results

I would expect a value of None to use the default value, or None should be removed from the type annotations entirely.

Reproducibility

Additional Information

@bestpantusen
Copy link

If possible, I'd like to work on this please.

@tomasr8
Copy link
Member

tomasr8 commented Dec 3, 2024

If possible, I'd like to work on this please.

Go for it! Feel free to ask if you need help :)

@bestpantusen
Copy link

@tomasr8 Please let me know if the PR looks good or missing anything!

@akx akx added this to the Babel 2.17 milestone Jan 8, 2025
@akx akx closed this as completed in #1164 Jan 9, 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
4 participants