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

2021-07-30 Thread Pierre Carbonnelle
Pierre Carbonnelle added the comment: I can live with the workaround, so, you can close the issue if you wish. As you say, maybe it's an issue with z3. Thank you for your time. -- ___ Python tracker _

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

2021-07-30 Thread Pierre Carbonnelle
Pierre Carbonnelle added the comment: As a work around, I had to use a temporary file (instead of a memory buffer): print("outside:", sys.stdout.encoding) with open("/tmp/log.txt", mode='w', encoding='utf-8') as buf: with redirect_stdout(buf) as f: print("inside: "

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

2021-07-30 Thread Steven D'Aprano
Steven D'Aprano added the comment: > I expect sys.stdout to have utf-8 encoding inside the redirect because > the buffer accepts unicode code points (not bytes) And the buffer stores unicode code points, not bytes, so why would there be an encoding? Just to get this out of the way, in case

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

2021-07-30 Thread Pierre Carbonnelle
Pierre Carbonnelle 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 in

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

2021-07-30 Thread Steven D'Aprano
Steven D'Aprano added the comment: Why do you expect UTF-8 inside the redirect_stdout block? io.StringIO doesn't have an encoding - it stores strings, not bytes. If z3-solver cannot deal with StringIO, then surely that's a bug in z3-solver? -- nosy: +steven.daprano _

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

2021-07-30 Thread Pierre Carbonnelle
New submission from Pierre Carbonnelle : The following code print("outside:", sys.stdout.encoding) with redirect_stdout(io.StringIO()) as f: print("inside: ", sys.stdout.encoding) print(f.getvalue()) yields: outside: utf-8 inside: None Because StringIO is a stri