gh-91954: Emit EncodingWarning from locale and subprocess (GH-91977)

locale.getpreferredencoding() and subprocess.Popen() emit EncodingWarning
This commit is contained in:
Inada Naoki 2022-04-30 15:53:29 +09:00 committed by GitHub
parent c7b7f12b86
commit 354ace8b07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 14 deletions

View file

@ -655,6 +655,11 @@ try:
except NameError:
def getpreferredencoding(do_setlocale=True):
"""Return the charset that the user is likely using."""
if sys.flags.warn_default_encoding:
import warnings
warnings.warn(
"UTF-8 Mode affects locale.getpreferredencoding(). Consider locale.getencoding() instead.",
EncodingWarning, 2)
if sys.flags.utf8_mode:
return 'utf-8'
return getencoding()
@ -663,6 +668,12 @@ else:
def getpreferredencoding(do_setlocale=True):
"""Return the charset that the user is likely using,
according to the system configuration."""
if sys.flags.warn_default_encoding:
import warnings
warnings.warn(
"UTF-8 Mode affects locale.getpreferredencoding(). Consider locale.getencoding() instead.",
EncodingWarning, 2)
if sys.flags.utf8_mode:
return 'utf-8'