From 3f3ae78c167a12c23ec4fa4681dd1d98bb3039e9 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Wed, 1 Mar 2023 08:25:31 +0200 Subject: Note that `Locale.parse()` does not accept `None` Refs #977 --- CHANGES.rst | 2 ++ babel/core.py | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 3a8f1d2..a8dcc7d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 ~~~~~~~~~~~~ diff --git a/babel/core.py b/babel/core.py index 6df5850..63fba0b 100644 --- a/babel/core.py +++ b/babel/core.py @@ -279,6 +279,15 @@ class Locale: >>> 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 -- cgit v1.2.1