diff options
author | Stefan Hoelzl <1478183+stefanhoelzl@users.noreply.github.com> | 2021-07-30 16:38:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-30 16:38:42 (GMT) |
commit | 80f07076294bc09a55ed76d9bbf307404eef25e6 (patch) | |
tree | 5a419fedf23bb306171060ae8ae19c97a0d80c72 /Lib/compileall.py | |
parent | 7cad0bee80a536c7e47f54cf43174175834f30a0 (diff) | |
download | cpython-80f07076294bc09a55ed76d9bbf307404eef25e6.zip cpython-80f07076294bc09a55ed76d9bbf307404eef25e6.tar.gz cpython-80f07076294bc09a55ed76d9bbf307404eef25e6.tar.bz2 |
bpo-44666: Use default encoding as fallback for compile_file (GH-27236)
When sys.stdout.encoding is None compile_file will fall back to
sys.getdefaultencoding to encode/decode error messages.
Co-authored-by: Stefan Hoelzl <stefan.hoelzl@posteo.de>
Co-authored-by: Mickaƫl Schoentgen <contact@tiger-222.fr>
Diffstat (limited to 'Lib/compileall.py')
-rw-r--r-- | Lib/compileall.py | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/Lib/compileall.py b/Lib/compileall.py index 61b4c5c..454465b 100644 --- a/Lib/compileall.py +++ b/Lib/compileall.py @@ -254,9 +254,8 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=0, else: print('*** ', end='') # escape non-printable characters in msg - msg = err.msg.encode(sys.stdout.encoding, - errors='backslashreplace') - msg = msg.decode(sys.stdout.encoding) + encoding = sys.stdout.encoding or sys.getdefaultencoding() + msg = err.msg.encode(encoding, errors='backslashreplace').decode(encoding) print(msg) except (SyntaxError, UnicodeError, OSError) as e: success = False |