Skip to content

Commit

Permalink
pythongh-103085: Fix python locale.getencoding not to emit deprecatio…
Browse files Browse the repository at this point in the history
…n warning (pythongh-103086)
  • Loading branch information
youknowone authored and warsaw committed Apr 11, 2023
1 parent b188cc8 commit 65efc81
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Lib/locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pure python :func:`locale.getencoding()` will not warn deprecation.

0 comments on commit 65efc81

Please sign in to comment.