gh-104783: Remove locale.resetlocale() function (#104784)

This commit is contained in:
Victor Stinner 2023-06-06 14:55:50 +02:00 committed by GitHub
parent c7bf74bacd
commit 0cb6b9b0db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 42 deletions

View file

@ -370,16 +370,6 @@ The :mod:`locale` module defines the following exception and functions:
encoding for the locale code just like :func:`setlocale`. 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) .. function:: strcoll(string1, string2)
Compares two strings according to the current :const:`LC_COLLATE` setting. As Compares two strings according to the current :const:`LC_COLLATE` setting. As

View file

@ -1079,6 +1079,7 @@ APIs:
* :class:`!configparser.LegacyInterpolation` (:gh:`90765`) * :class:`!configparser.LegacyInterpolation` (:gh:`90765`)
* :func:`locale.getdefaultlocale` (:gh:`90817`) * :func:`locale.getdefaultlocale` (:gh:`90817`)
* ``locale.resetlocale()`` (:gh:`90817`)
* :meth:`!turtle.RawTurtle.settiltangle` (:gh:`50096`) * :meth:`!turtle.RawTurtle.settiltangle` (:gh:`50096`)
* :func:`!unittest.findTestCases` (:gh:`50096`) * :func:`!unittest.findTestCases` (:gh:`50096`)
* :func:`!unittest.getTestCaseNames` (:gh:`50096`) * :func:`!unittest.getTestCaseNames` (:gh:`50096`)

View file

@ -306,6 +306,10 @@ Removed
added in Python 3.8 and the old macros were deprecated in Python 3.11. added in Python 3.8 and the old macros were deprecated in Python 3.11.
(Contributed by Irit Katriel in :gh:`105111`.) (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 Porting to Python 3.13
====================== ======================

View file

@ -25,7 +25,7 @@ import functools
# Yuck: LC_MESSAGES is non-standard: can't tell whether it exists before # 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. # trying the import. So __all__ is also fiddled at the end of the file.
__all__ = ["getlocale", "getdefaultlocale", "getpreferredencoding", "Error", __all__ = ["getlocale", "getdefaultlocale", "getpreferredencoding", "Error",
"setlocale", "resetlocale", "localeconv", "strcoll", "strxfrm", "setlocale", "localeconv", "strcoll", "strxfrm",
"str", "atof", "atoi", "format_string", "currency", "str", "atof", "atoi", "format_string", "currency",
"normalize", "LC_CTYPE", "LC_COLLATE", "LC_TIME", "LC_MONETARY", "normalize", "LC_CTYPE", "LC_COLLATE", "LC_TIME", "LC_MONETARY",
"LC_NUMERIC", "LC_ALL", "CHAR_MAX", "getencoding"] "LC_NUMERIC", "LC_ALL", "CHAR_MAX", "getencoding"]
@ -612,26 +612,6 @@ def setlocale(category, locale=None):
locale = normalize(_build_localename(locale)) locale = normalize(_build_localename(locale))
return _setlocale(category, 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: try:
from _locale import getencoding from _locale import getencoding
@ -1729,17 +1709,6 @@ def _print_locale():
print(' Encoding: ', enc or '(undefined)') print(' Encoding: ', enc or '(undefined)')
print() 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: try:
setlocale(LC_ALL, "") setlocale(LC_ALL, "")
except: except:

View file

@ -0,0 +1,2 @@
Remove ``locale.resetlocale()`` function deprecated in Python 3.11.
Patch by Victor Stinner.