summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Doc/library/locale.rst2
-rw-r--r--Doc/whatsnew/3.11.rst6
-rw-r--r--Lib/locale.py6
-rw-r--r--Lib/test/test_locale.py3
-rw-r--r--Misc/NEWS.d/next/Library/2022-02-06-17-57-45.bpo-46659.zTmkoQ.rst4
5 files changed, 20 insertions, 1 deletions
diff --git a/Doc/library/locale.rst b/Doc/library/locale.rst
index 60d0c59..1b14734 100644
--- a/Doc/library/locale.rst
+++ b/Doc/library/locale.rst
@@ -301,6 +301,8 @@ The :mod:`locale` module defines the following exception and functions:
*language code* and *encoding* may be ``None`` if their values cannot be
determined.
+ .. deprecated:: 3.11 3.13
+
.. function:: getlocale(category=LC_CTYPE)
diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst
index 85f12fe..32f021f 100644
--- a/Doc/whatsnew/3.11.rst
+++ b/Doc/whatsnew/3.11.rst
@@ -486,6 +486,12 @@ Deprecated
(Contributed by Hugo van Kemenade in :issue:`45173`.)
+* The :func:`locale.getdefaultlocale` function is deprecated and will be
+ 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`.)
+
Removed
=======
diff --git a/Lib/locale.py b/Lib/locale.py
index 4bd31c9..a710f27 100644
--- a/Lib/locale.py
+++ b/Lib/locale.py
@@ -555,6 +555,12 @@ def getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')):
"""
+ import warnings
+ warnings.warn(
+ "Use setlocale(), getpreferredencoding(False) and getlocale() instead",
+ DeprecationWarning, stacklevel=2
+ )
+
try:
# check if it's supported by the _locale module
import _locale
diff --git a/Lib/test/test_locale.py b/Lib/test/test_locale.py
index f844e62..2a3b0ac 100644
--- a/Lib/test/test_locale.py
+++ b/Lib/test/test_locale.py
@@ -518,7 +518,8 @@ class TestMiscellaneous(unittest.TestCase):
os.environ['LC_CTYPE'] = 'UTF-8'
- self.assertEqual(locale.getdefaultlocale(), (None, 'UTF-8'))
+ with check_warnings(('', DeprecationWarning)):
+ self.assertEqual(locale.getdefaultlocale(), (None, 'UTF-8'))
finally:
for k in orig_env:
diff --git a/Misc/NEWS.d/next/Library/2022-02-06-17-57-45.bpo-46659.zTmkoQ.rst b/Misc/NEWS.d/next/Library/2022-02-06-17-57-45.bpo-46659.zTmkoQ.rst
new file mode 100644
index 0000000..6fd9a53
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-02-06-17-57-45.bpo-46659.zTmkoQ.rst
@@ -0,0 +1,4 @@
+The :func:`locale.getdefaultlocale` function is deprecated and will be removed
+in Python 3.13. Use :func:`locale.setlocale`,
+:func:`locale.getpreferredencoding(False) <locale.getpreferredencoding>` and
+:func:`locale.getlocale` functions instead. Patch by Victor Stinner.