]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46659: Deprecate locale.getdefaultlocale() (GH-31206)
authorVictor Stinner <vstinner@python.org>
Tue, 22 Feb 2022 21:06:43 +0000 (22:06 +0100)
committerGitHub <noreply@github.com>
Tue, 22 Feb 2022 21:06:43 +0000 (22:06 +0100)
The locale.getdefaultlocale() function is deprecated and will be
removed in Python 3.13. Use locale.setlocale(),
locale.getpreferredencoding(False) and locale.getlocale() functions
instead.

Doc/library/locale.rst
Doc/whatsnew/3.11.rst
Lib/locale.py
Lib/test/test_locale.py
Misc/NEWS.d/next/Library/2022-02-06-17-57-45.bpo-46659.zTmkoQ.rst [new file with mode: 0644]

index 60d0c59d017c73988288093183b4be4812a6de35..1b147342cef1426b366bd44fb2fe5f835f126d16 100644 (file)
@@ -301,6 +301,8 @@ The :mod:`locale` module defines the following exception and functions:
    *language code* and *encoding* may be ``None`` if their values cannot be
    determined.
 
+   .. deprecated:: 3.11 3.13
+
 
 .. function:: getlocale(category=LC_CTYPE)
 
index 85f12fe8b4fc7f1511bd700f60c8c1ba004cda62..32f021f03cccecd92129cb09e9cb05255a5834e6 100644 (file)
@@ -486,6 +486,12 @@ Deprecated
 
   (Contributed by Hugo van Kemenade in :issue:`45173`.)
 
+* The :func:`locale.getdefaultlocale` function is deprecated and will be
+  removed in Python 3.13. Use :func:`locale.setlocale`,
+  :func:`locale.getpreferredencoding(False) <locale.getpreferredencoding>` and
+  :func:`locale.getlocale` functions instead.
+  (Contributed by Victor Stinner in :issue:`46659`.)
+
 
 Removed
 =======
index 4bd31c9fa2cdf71b69103e489f29e822ddd3e862..a710f27a807b090f5651291fc78d45cbb9a9048f 100644 (file)
@@ -555,6 +555,12 @@ def getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')):
 
     """
 
+    import warnings
+    warnings.warn(
+        "Use setlocale(), getpreferredencoding(False) and getlocale() instead",
+        DeprecationWarning, stacklevel=2
+    )
+
     try:
         # check if it's supported by the _locale module
         import _locale
index f844e62ca2e72be8245fcc779fa9e2d18db8fd6a..2a3b0acc6bd606c44f0ec44f51ef845a73b8fd3c 100644 (file)
@@ -518,7 +518,8 @@ class TestMiscellaneous(unittest.TestCase):
 
             os.environ['LC_CTYPE'] = 'UTF-8'
 
-            self.assertEqual(locale.getdefaultlocale(), (None, 'UTF-8'))
+            with check_warnings(('', DeprecationWarning)):
+                self.assertEqual(locale.getdefaultlocale(), (None, 'UTF-8'))
 
         finally:
             for k in orig_env:
diff --git a/Misc/NEWS.d/next/Library/2022-02-06-17-57-45.bpo-46659.zTmkoQ.rst b/Misc/NEWS.d/next/Library/2022-02-06-17-57-45.bpo-46659.zTmkoQ.rst
new file mode 100644 (file)
index 0000000..6fd9a53
--- /dev/null
@@ -0,0 +1,4 @@
+The :func:`locale.getdefaultlocale` function is deprecated and will be removed
+in Python 3.13. Use :func:`locale.setlocale`,
+:func:`locale.getpreferredencoding(False) <locale.getpreferredencoding>` and
+:func:`locale.getlocale` functions instead.  Patch by Victor Stinner.