From 0cb6b9b0db5df6b3f902e86eb3d4a1e504afb851 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 6 Jun 2023 14:55:50 +0200 Subject: [PATCH] gh-104783: Remove locale.resetlocale() function (#104784) --- Doc/library/locale.rst | 10 ------ Doc/whatsnew/3.12.rst | 1 + Doc/whatsnew/3.13.rst | 4 +++ Lib/locale.py | 33 +------------------ ...-05-23-04-01-27.gh-issue-104783.QyhIoq.rst | 2 ++ 5 files changed, 8 insertions(+), 42 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2023-05-23-04-01-27.gh-issue-104783.QyhIoq.rst diff --git a/Doc/library/locale.rst b/Doc/library/locale.rst index f2abb3638a141f..afd5677deac3f8 100644 --- a/Doc/library/locale.rst +++ b/Doc/library/locale.rst @@ -370,16 +370,6 @@ The :mod:`locale` module defines the following exception and functions: encoding for the locale code just like :func:`setlocale`. -.. function:: resetlocale(category=LC_ALL) - - Sets the locale for *category* to the default setting. - - The default setting is determined by calling :func:`getdefaultlocale`. - *category* defaults to :const:`LC_ALL`. - - .. deprecated-removed:: 3.11 3.13 - - .. function:: strcoll(string1, string2) Compares two strings according to the current :const:`LC_COLLATE` setting. As diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index af62602a40098e..7e7942550a797b 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -1079,6 +1079,7 @@ APIs: * :class:`!configparser.LegacyInterpolation` (:gh:`90765`) * :func:`locale.getdefaultlocale` (:gh:`90817`) +* ``locale.resetlocale()`` (:gh:`90817`) * :meth:`!turtle.RawTurtle.settiltangle` (:gh:`50096`) * :func:`!unittest.findTestCases` (:gh:`50096`) * :func:`!unittest.getTestCaseNames` (:gh:`50096`) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index da6c8c97872896..9cfccdeac787d5 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -306,6 +306,10 @@ Removed added in Python 3.8 and the old macros were deprecated in Python 3.11. (Contributed by Irit Katriel in :gh:`105111`.) +* Remove ``locale.resetlocale()`` function deprecated in Python 3.11: + use ``locale.setlocale(locale.LC_ALL, "")`` instead. + (Contributed by Victor Stinner in :gh:`104783`.) + Porting to Python 3.13 ====================== diff --git a/Lib/locale.py b/Lib/locale.py index e94f0d1acbaa7d..019796730071a5 100644 --- a/Lib/locale.py +++ b/Lib/locale.py @@ -25,7 +25,7 @@ # Yuck: LC_MESSAGES is non-standard: can't tell whether it exists before # trying the import. So __all__ is also fiddled at the end of the file. __all__ = ["getlocale", "getdefaultlocale", "getpreferredencoding", "Error", - "setlocale", "resetlocale", "localeconv", "strcoll", "strxfrm", + "setlocale", "localeconv", "strcoll", "strxfrm", "str", "atof", "atoi", "format_string", "currency", "normalize", "LC_CTYPE", "LC_COLLATE", "LC_TIME", "LC_MONETARY", "LC_NUMERIC", "LC_ALL", "CHAR_MAX", "getencoding"] @@ -612,26 +612,6 @@ def setlocale(category, locale=None): locale = normalize(_build_localename(locale)) return _setlocale(category, locale) -def resetlocale(category=LC_ALL): - - """ Sets the locale for category to the default setting. - - The default setting is determined by calling - getdefaultlocale(). category defaults to LC_ALL. - - """ - 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: from _locale import getencoding @@ -1729,17 +1709,6 @@ def _init_categories(categories=categories): print(' Encoding: ', enc or '(undefined)') print() - print() - print('Locale settings after calling resetlocale():') - print('-'*72) - resetlocale() - for name,category in categories.items(): - print(name, '...') - lang, enc = getlocale(category) - print(' Language: ', lang or '(undefined)') - print(' Encoding: ', enc or '(undefined)') - print() - try: setlocale(LC_ALL, "") except: diff --git a/Misc/NEWS.d/next/Library/2023-05-23-04-01-27.gh-issue-104783.QyhIoq.rst b/Misc/NEWS.d/next/Library/2023-05-23-04-01-27.gh-issue-104783.QyhIoq.rst new file mode 100644 index 00000000000000..23670e8fe14d3d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-05-23-04-01-27.gh-issue-104783.QyhIoq.rst @@ -0,0 +1,2 @@ +Remove ``locale.resetlocale()`` function deprecated in Python 3.11. +Patch by Victor Stinner.