Thanks to visit codestin.com
Credit goes to github.com

Skip to content

GH-103085: Fix python locale.getencoding not to emit deprecation warning #103086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.