summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-02-22 21:06:43 (GMT)
committerGitHub <noreply@github.com>2022-02-22 21:06:43 (GMT)
commitb899126094731bc49fecb61f2c1b7557d74ca839 (patch)
tree0fcb5dbe42994f32e7caf03514cbfd11fdca825b /Lib
parentccbe8045faf6e63d36229ea4e1b9298572cda126 (diff)
downloadcpython-b899126094731bc49fecb61f2c1b7557d74ca839.zip
cpython-b899126094731bc49fecb61f2c1b7557d74ca839.tar.gz
cpython-b899126094731bc49fecb61f2c1b7557d74ca839.tar.bz2
bpo-46659: Deprecate locale.getdefaultlocale() (GH-31206)
The locale.getdefaultlocale() function is deprecated and will be removed in Python 3.13. Use locale.setlocale(), locale.getpreferredencoding(False) and locale.getlocale() functions instead.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/locale.py6
-rw-r--r--Lib/test/test_locale.py3
2 files changed, 8 insertions, 1 deletions
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: