[Python-checkins] gh-103085: Fix python locale.getencoding not to emit deprecation warning (gh-103086)

corona10 webhook-mailer at python.org
Thu Mar 30 12:24:10 EDT 2023


https://github.com/python/cpython/commit/21e9de3bf0ecf32cd61296009518bfb9fdfcd04f
commit: 21e9de3bf0ecf32cd61296009518bfb9fdfcd04f
branch: main
author: Jeong, YunWon <69878+youknowone at users.noreply.github.com>
committer: corona10 <donghee.na92 at gmail.com>
date: 2023-03-31T01:23:43+09:00
summary:

gh-103085: Fix python locale.getencoding not to emit deprecation warning (gh-103086)

files:
A Misc/NEWS.d/next/Library/2023-03-28-15-12-53.gh-issue-103085.DqNehf.rst
M Lib/locale.py

diff --git a/Lib/locale.py b/Lib/locale.py
index c2c7a04b2807..4127d9174659 100644
--- a/Lib/locale.py
+++ b/Lib/locale.py
@@ -545,7 +545,9 @@ def getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')):
         "Use setlocale(), getencoding() and getlocale() instead",
         DeprecationWarning, stacklevel=2
     )
+    return _getdefaultlocale(envvars)
 
+def _getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')):
     try:
         # check if it's supported by the _locale module
         import _locale
@@ -639,7 +641,7 @@ def getencoding():
             # On Android langinfo.h and CODESET are missing, and UTF-8 is
             # always used in mbstowcs() and wcstombs().
             return 'utf-8'
-        encoding = getdefaultlocale()[1]
+        encoding = _getdefaultlocale()[1]
         if encoding is None:
             # LANG not set, default to UTF-8
             encoding = 'utf-8'
diff --git a/Misc/NEWS.d/next/Library/2023-03-28-15-12-53.gh-issue-103085.DqNehf.rst b/Misc/NEWS.d/next/Library/2023-03-28-15-12-53.gh-issue-103085.DqNehf.rst
new file mode 100644
index 000000000000..fa07fa5226c0
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-03-28-15-12-53.gh-issue-103085.DqNehf.rst
@@ -0,0 +1 @@
+Pure python :func:`locale.getencoding()` will not warn deprecation.



More information about the Python-checkins mailing list