Skip to content

locale parameter cannot be None #1156

@injust

Description

@injust

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions