[issue44774] incorrect sys.stdout.encoding within a io.StringIO buffer

Pierre Carbonnelle report at bugs.python.org
Fri Jul 30 07:09:39 EDT 2021


Pierre Carbonnelle <pierre.carbonnelle at gmail.com> added the comment:

I expect sys.stdout to have utf-8 encoding inside the redirect because the buffer accepts unicode code points (not bytes), just as it does outside of the redirect.  In other words, I expect the 'encoding' attribute of sys.stdout to have the same value inside and outside this redirect.

It so happens that sys.stdout is an io.StringIO() object inside the redirect.  The getvalue() method on this object returns a string (not a bytes), i.e. a sequence of unicode points.

StringIO inherits from TextIOBase, which has an 'encoding' attribute.  For some reason, the encoding of a StringIO object is None, which is inconsistent with its semantics: it should be 'uft-8'.

----------

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


More information about the Python-bugs-list mailing list