summaryrefslogtreecommitdiffstats
path: root/Lib/locale.py
diff options
context:
space:
mode:
authorInada Naoki <songofacandy@gmail.com>2022-04-30 06:53:29 (GMT)
committerGitHub <noreply@github.com>2022-04-30 06:53:29 (GMT)
commit354ace8b07e7d445fd2de713b6af1271536adce0 (patch)
tree6827337429f78065731f6136975b4bea47dd8e0d /Lib/locale.py
parentc7b7f12b8609f932a23a9bc96a5de7cd9ecd5723 (diff)
downloadcpython-354ace8b07e7d445fd2de713b6af1271536adce0.zip
cpython-354ace8b07e7d445fd2de713b6af1271536adce0.tar.gz
cpython-354ace8b07e7d445fd2de713b6af1271536adce0.tar.bz2
gh-91954: Emit EncodingWarning from locale and subprocess (GH-91977)
locale.getpreferredencoding() and subprocess.Popen() emit EncodingWarning
Diffstat (limited to 'Lib/locale.py')
-rw-r--r--Lib/locale.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/locale.py b/Lib/locale.py
index 170e5ee..25eb75ac 100644
--- a/Lib/locale.py
+++ b/Lib/locale.py
@@ -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'