Skip to content

Commit 83940c0

Browse files
gh-90817: Deprecate explicitly locale.resetlocale() (GH-93196)
The function was already deprecated in Python 3.11 since it calls locale.getdefaultlocale() which was deprecated in Python 3.11. (cherry picked from commit bf58cd0) Co-authored-by: Victor Stinner <[email protected]>
1 parent 37a7f1b commit 83940c0

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

Doc/library/locale.rst

+2
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ The :mod:`locale` module defines the following exception and functions:
375375
The default setting is determined by calling :func:`getdefaultlocale`.
376376
*category* defaults to :const:`LC_ALL`.
377377

378+
.. deprecated:: 3.11 3.13
379+
378380

379381
.. function:: strcoll(string1, string2)
380382

Doc/whatsnew/3.11.rst

+5-1
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,11 @@ Deprecated
12211221
removed in Python 3.13. Use :func:`locale.setlocale`,
12221222
:func:`locale.getpreferredencoding(False) <locale.getpreferredencoding>` and
12231223
:func:`locale.getlocale` functions instead.
1224-
(Contributed by Victor Stinner in :issue:`46659`.)
1224+
(Contributed by Victor Stinner in :gh:`90817`.)
1225+
1226+
* The :func:`locale.resetlocale` function is deprecated and will be
1227+
removed in Python 3.13. Use ``locale.setlocale(locale.LC_ALL, "")`` instead.
1228+
(Contributed by Victor Stinner in :gh:`90817`.)
12251229

12261230
* The :mod:`asynchat`, :mod:`asyncore` and :mod:`smtpd` modules have been
12271231
deprecated since at least Python 3.6. Their documentation and deprecation

Lib/locale.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,17 @@ def resetlocale(category=LC_ALL):
633633
getdefaultlocale(). category defaults to LC_ALL.
634634
635635
"""
636-
_setlocale(category, _build_localename(getdefaultlocale()))
636+
import warnings
637+
warnings.warn(
638+
'Use locale.setlocale(locale.LC_ALL, "") instead',
639+
DeprecationWarning, stacklevel=2
640+
)
641+
642+
with warnings.catch_warnings():
643+
warnings.simplefilter('ignore', category=DeprecationWarning)
644+
loc = getdefaultlocale()
645+
646+
_setlocale(category, _build_localename(loc))
637647

638648

639649
try:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The :func:`locale.resetlocale` function is deprecated and will be removed in
2+
Python 3.13. Use ``locale.setlocale(locale.LC_ALL, "")`` instead. Patch by
3+
Victor Stinner.

0 commit comments

Comments
 (0)