Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Labels
Description
Currently,TextIOWrapper.__init__ callsos.device_encoding(file.fileno()) when encoding is not specified and fileno is 0-2 (e.g.open(0)).
However,sys.stdin,stdout, andstderr don't use it even whenPYTHONLEGACYWINDOWSSTDIO=1.config->stdio_encoding is initialized byGetACP(), andcreate_stdio() passesconfig->stdio_encoding toTextIOWrapper.
How about removingos.device_encoding(file.fileno()) fromTextIOWrapper.__init__()?
- Thanks to WindowsConsoleIO, most user don't use the console encoding at all.
- WindowsConsoleIO require UTF-8. So
TextIOWrapper(sys.stdout)cause mojibake when sys.stdout is WindowsConsoleIO - The only use case of
PYTHONLEGACYWINDOWSSTDIOI know isthis. But this use case don't create TextIOWrapper for fd=0,1,2. - This TextIOWrapper behavior is never documented. It makes
TextIOWrapper.__init__complicated and inconsistent. - If we want to use console encoding for stdio when PYTHONLEGACYWINDOWSSTDIO is set, we can fix it in
create_stdio().create_stdio()has special case for WindowsConsoleIO already. (here)