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

Note that Locale.parse() does not accept None #978

Merged
merged 1 commit into from Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -18,6 +18,8 @@ Deprecations & breaking changes

* Python 3.6 is no longer supported (:gh:`919`) - Aarni Koskela
* The `get_next_timezone_transition` function is no more (:gh:`958`) - Aarni Koskela
* `Locale.parse()` will no longer return `None`; it will always return a Locale or raise an exception.
Passing in `None`, though technically allowed by the typing, will raise. (:gh:`966`)

New features
~~~~~~~~~~~~
Expand Down
9 changes: 9 additions & 0 deletions babel/core.py
Expand Up @@ -279,6 +279,15 @@ def parse(
>>> Locale.parse(l)
Locale('de', territory='DE')

If the `identifier` parameter is neither of these, such as `None`
e.g. because a default locale identifier could not be determined,
a `TypeError` is raised:

>>> Locale.parse(None)
Traceback (most recent call last):
...
TypeError: ...

This also can perform resolving of likely subtags which it does
by default. This is for instance useful to figure out the most
likely locale for a territory you can use ``'und'`` as the
Expand Down