From 354ace8b07e7d445fd2de713b6af1271536adce0 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Sat, 30 Apr 2022 15:53:29 +0900 Subject: gh-91954: Emit EncodingWarning from locale and subprocess (GH-91977) locale.getpreferredencoding() and subprocess.Popen() emit EncodingWarning --- Lib/locale.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'Lib/locale.py') diff --git a/Lib/locale.py b/Lib/locale.py index 170e5eea45b..25eb75ac65a 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' -- cgit v1.2.3