Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Remove console encoding support from TextIOWrapper. #91526

Closed
@methane

Description

@methane

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. SoTextIOWrapper(sys.stdout) cause mojibake when sys.stdout is WindowsConsoleIO
  • The only use case ofPYTHONLEGACYWINDOWSSTDIO I know isthis. But this use case don't create TextIOWrapper for fd=0,1,2.
  • This TextIOWrapper behavior is never documented. It makesTextIOWrapper.__init__ complicated and inconsistent.
  • If we want to use console encoding for stdio when PYTHONLEGACYWINDOWSSTDIO is set, we can fix it increate_stdio().create_stdio() has special case for WindowsConsoleIO already. (here)

Ping:@vstinner@eryksun@zooba

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp