Skip to content

[io] Windows legacy mode mistakenly ignores the device encoding #86427

Description

@eryksun
BPO 42261
Nosy @pfmoore, @vstinner, @tjguk, @zware, @eryksun, @zooba

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2020-11-04.15:20:48.448>
labels = ['interpreter-core', 'type-bug', '3.8', '3.9', 'expert-IO', '3.10', 'OS-windows']
title = 'Windows legacy I/O mode mistakenly ignores the device encoding'
updated_at = <Date 2020-11-04.16:50:47.706>
user = 'https://github.com/eryksun'

bugs.python.org fields:

activity = <Date 2020-11-04.16:50:47.706>
actor = 'eryksun'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Interpreter Core', 'Windows', 'IO']
creation = <Date 2020-11-04.15:20:48.448>
creator = 'eryksun'
dependencies = []
files = []
hgrepos = []
issue_num = 42261
keywords = []
message_count = 5.0
messages = ['380329', '380330', '380333', '380335', '380343']
nosy_count = 6.0
nosy_names = ['paul.moore', 'vstinner', 'tim.golden', 'zach.ware', 'eryksun', 'steve.dower']
pr_nums = []
priority = 'normal'
resolution = None
stage = 'needs patch'
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue42261'
versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

Linked PRs

Activity

  1. eryksun commented on Nov 4, 2020

    @eryksun
    ContributorAuthor

    In Python 3.8+, legacy standard I/O mode uses the process code page from GetACP instead of the correct device encoding from GetConsoleCP and GetConsoleOutputCP. For example:

    C:\>chcp 850
    Active code page: 850
    C:\>set PYTHONLEGACYWINDOWSSTDIO=1
    
    C:\>py -3.7 -c "import sys; print(sys.stdin.encoding)"
    cp850
    C:\>py -3.8 -c "import sys; print(sys.stdin.encoding)"
    cp1252
    C:\>py -3.9 -c "import sys; print(sys.stdin.encoding)"
    cp1252
    

    This is based on config_init_stdio_encoding() in Python/initconfig.c, which sets config->stdio_encoding via config_get_locale_encoding(). Cannot config->stdio_encoding be set to NULL for default behavior?

    Computing this ahead of time would require separate encodings config->stdin_encoding, config->stdout_encoding, and config->stderr_encoding. And _Py_device_encoding would have to be duplicated as something like config_get_device_encoding(PyConfig *config, int fd, wchar_t **device_encoding).

  2. 7 remaining items

  3. added
    3.13only security fixes
    3.14bugs and security fixes
    3.15pre-release feature fixes, bugs and security fixes
    3.16new features, bugs and security fixes
    and removed on Aug 9, 2026
  4. added 5 commits that reference this issue on Aug 29, 2026
  5. added a commit that references this issue on Sep 12, 2026
  6. added a commit that references this issue on Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixes3.14bugs and security fixes3.15pre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixesOS-windowsinterpreter-core(Objects, Python, Grammar, and Parser dirs)topic-IOtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions