[New-bugs-announce] [issue44666] compileall.compile_file fails when sys.stdout is redirected to StringIO

Stefan Hölzl report at bugs.python.org
Sun Jul 18 04:57:11 EDT 2021


New submission from Stefan Hölzl <stefanh+pythonbugs at posteo.de>:

compile_files tries to escape non-printable characters in error messages by using sys.stdout.encoding
https://github.com/python/cpython/blob/main/Lib/compileall.py#L256

when using contextlib.redirect_stdout to redirect stdout to io.StringIO as explained in the documentation
https://docs.python.org/3/library/contextlib.html#contextlib.redirect_stdout

compile_file fails, because io.StringIO has encoding set to None.

see the attached file to reproduce the issue

----------
components: Library (Lib)
files: compile_file_bug.py
messages: 397743
nosy: stefanhoelzl
priority: normal
severity: normal
status: open
title: compileall.compile_file fails when sys.stdout is redirected to StringIO
type: crash
versions: Python 3.10, Python 3.11, Python 3.6, Python 3.7, Python 3.8, Python 3.9
Added file: https://bugs.python.org/file50156/compile_file_bug.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44666>
_______________________________________


More information about the New-bugs-announce mailing list