summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-05-25 20:04:06 (GMT)
committerGitHub <noreply@github.com>2022-05-25 20:04:06 (GMT)
commitbf58cd01b313837511d9399f18588ccd2e5dc5a9 (patch)
treea80d7beab81640cee2c4ee77ffff6f179d2fa2d2
parent854db1a6061c83d80a3f1e4e87f043b521719920 (diff)
downloadcpython-bf58cd01b313837511d9399f18588ccd2e5dc5a9.zip
cpython-bf58cd01b313837511d9399f18588ccd2e5dc5a9.tar.gz
cpython-bf58cd01b313837511d9399f18588ccd2e5dc5a9.tar.bz2
gh-90817: Deprecate explicitly locale.resetlocale() (#93196)
The function was already deprecated in Python 3.11 since it calls locale.getdefaultlocale() which was deprecated in Python 3.11.
-rw-r--r--Doc/library/locale.rst2
-rw-r--r--Doc/whatsnew/3.11.rst6
-rw-r--r--Lib/locale.py12
-rw-r--r--Misc/NEWS.d/next/Library/2022-05-25-02-45-41.gh-issue-90817.yxANgU.rst3
4 files changed, 21 insertions, 2 deletions
diff --git a/Doc/library/locale.rst b/Doc/library/locale.rst
index 77a3e03..112f0ba 100644
--- a/Doc/library/locale.rst
+++ b/Doc/library/locale.rst
@@ -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)
diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst
index c7ff6ca..24d1343 100644
--- a/Doc/whatsnew/3.11.rst
+++ b/Doc/whatsnew/3.11.rst
@@ -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
diff --git a/Lib/locale.py b/Lib/locale.py
index 25eb75ac..7a7694e 100644
--- a/Lib/locale.py
+++ b/Lib/locale.py
@@ -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
index 0000000..06937e8
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-05-25-02-45-41.gh-issue-90817.yxANgU.rst
@@ -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.