]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-90817: Deprecate explicitly locale.resetlocale() (#93196)
authorVictor Stinner <vstinner@python.org>
Wed, 25 May 2022 20:04:06 +0000 (22:04 +0200)
committerGitHub <noreply@github.com>
Wed, 25 May 2022 20:04:06 +0000 (22:04 +0200)
The function was already deprecated in Python 3.11 since it calls
locale.getdefaultlocale() which was deprecated in Python 3.11.

Doc/library/locale.rst
Doc/whatsnew/3.11.rst
Lib/locale.py
Misc/NEWS.d/next/Library/2022-05-25-02-45-41.gh-issue-90817.yxANgU.rst [new file with mode: 0644]

index 77a3e036841baa34c9a0c776181548e2953e0c42..112f0bae78daf91ef738423cf7a3ac213cb3de21 100644 (file)
@@ -375,6 +375,8 @@ The :mod:`locale` module defines the following exception and functions:
    The default setting is determined by calling :func:`getdefaultlocale`.
    *category* defaults to :const:`LC_ALL`.
 
+   .. deprecated:: 3.11 3.13
+
 
 .. function:: strcoll(string1, string2)
 
index c7ff6ca4938c7079684898a06e5c87f1154c749f..24d1343689c98f44d05e6604f9f90682f479db7f 100644 (file)
@@ -1221,7 +1221,11 @@ Deprecated
   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`.)
+  (Contributed by Victor Stinner in :gh:`90817`.)
+
+* The :func:`locale.resetlocale` function is deprecated and will be
+  removed in Python 3.13. Use ``locale.setlocale(locale.LC_ALL, "")`` instead.
+  (Contributed by Victor Stinner in :gh:`90817`.)
 
 * The :mod:`asynchat`, :mod:`asyncore` and  :mod:`smtpd` modules have been
   deprecated since at least Python 3.6. Their documentation and deprecation
index 25eb75ac65a32ba59ef8cf07d874435b69262544..7a7694e1bfb71cc5a84e6f9df1eae67549a094d4 100644 (file)
@@ -633,7 +633,17 @@ def resetlocale(category=LC_ALL):
         getdefaultlocale(). category defaults to LC_ALL.
 
     """
-    _setlocale(category, _build_localename(getdefaultlocale()))
+    import warnings
+    warnings.warn(
+        'Use locale.setlocale(locale.LC_ALL, "") instead',
+        DeprecationWarning, stacklevel=2
+    )
+
+    with warnings.catch_warnings():
+        warnings.simplefilter('ignore', category=DeprecationWarning)
+        loc = getdefaultlocale()
+
+    _setlocale(category, _build_localename(loc))
 
 
 try:
diff --git a/Misc/NEWS.d/next/Library/2022-05-25-02-45-41.gh-issue-90817.yxANgU.rst b/Misc/NEWS.d/next/Library/2022-05-25-02-45-41.gh-issue-90817.yxANgU.rst
new file mode 100644 (file)
index 0000000..06937e8
--- /dev/null
@@ -0,0 +1,3 @@
+The :func:`locale.resetlocale` function is deprecated and will be removed in
+Python 3.13. Use ``locale.setlocale(locale.LC_ALL, "")`` instead. Patch by
+Victor Stinner.