Skip to content

Commit

Permalink
gh-90817: Deprecate explicitly locale.resetlocale() (GH-93196)
Browse files Browse the repository at this point in the history
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 <vstinner@python.org>
  • Loading branch information
miss-islington and vstinner committed May 25, 2022
1 parent 37a7f1b commit 83940c0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Doc/library/locale.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 5 additions & 1 deletion Doc/whatsnew/3.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion Lib/locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 83940c0

Please sign in to comment.