-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed
Labels
Description
Currently, TextIOWrapper.__init__ calls os.device_encoding(file.fileno()) when encoding is not specified and fileno is 0-2 (e.g. open(0)).
However, sys.stdin, stdout, and stderr don't use it even when PYTHONLEGACYWINDOWSSTDIO=1.
config->stdio_encoding is initialized by GetACP(), and create_stdio() passes config->stdio_encoding to TextIOWrapper.
How about removing os.device_encoding(file.fileno()) from TextIOWrapper.__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 is this. 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)