Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os.device_encoding() doesn't respect the UTF-8 Mode #86402

Closed
vstinner opened this issue Nov 1, 2020 · 8 comments
Closed

os.device_encoding() doesn't respect the UTF-8 Mode #86402

vstinner opened this issue Nov 1, 2020 · 8 comments
Labels
3.10 only security fixes stdlib Python modules in the Lib dir

Comments

@vstinner
Copy link
Member

vstinner commented Nov 1, 2020

BPO 42236
Nosy @vstinner, @methane
PRs
  • bpo-42236: Enhance _locale._get_locale_encoding() #23083
  • bpo-42236: Use UTF-8 encoding if nl_langinfo(CODESET) fails #23086
  • bpo-42236: Enhance init and encoding documentation #23109
  • bpo-42236: os.device_encoding() respects UTF-8 Mode #23119
  • 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 = <Date 2020-11-04.10:26:56.126>
    created_at = <Date 2020-11-01.18:12:56.742>
    labels = ['library', '3.10']
    title = "os.device_encoding() doesn't respect the UTF-8 Mode"
    updated_at = <Date 2020-11-04.10:26:56.125>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2020-11-04.10:26:56.125>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-11-04.10:26:56.126>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2020-11-01.18:12:56.742>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 42236
    keywords = ['patch']
    message_count = 8.0
    messages = ['380156', '380158', '380159', '380166', '380234', '380261', '380313', '380314']
    nosy_count = 2.0
    nosy_names = ['vstinner', 'methane']
    pr_nums = ['23083', '23086', '23109', '23119']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue42236'
    versions = ['Python 3.10']

    @vstinner
    Copy link
    Member Author

    vstinner commented Nov 1, 2020

    When the UTF-8 Mode is enabled, sys.stdout.encoding is always UTF-8, whereas os.devide_encoding(sys.stdout.fileno()) returns the locale encoding. os.devide_encoding() must return UTF-8 when the UTF-8 Mode is used.

    @vstinner vstinner added 3.10 only security fixes stdlib Python modules in the Lib dir labels Nov 1, 2020
    @vstinner
    Copy link
    Member Author

    vstinner commented Nov 1, 2020

    In bpo-42208, I added C _Py_GetLocaleEncoding() function and Python _locale._get_locale_encoding() function.

    @vstinner
    Copy link
    Member Author

    vstinner commented Nov 1, 2020

    New changeset 82458b6 by Victor Stinner in branch 'master':
    bpo-42236: Enhance _locale._get_locale_encoding() (GH-23083)
    82458b6

    @vstinner
    Copy link
    Member Author

    vstinner commented Nov 1, 2020

    New changeset e662c39 by Victor Stinner in branch 'master':
    bpo-42236: Use UTF-8 encoding if nl_langinfo(CODESET) fails (GH-23086)
    e662c39

    @vstinner
    Copy link
    Member Author

    vstinner commented Nov 2, 2020

    New changeset 4b9aad4 by Victor Stinner in branch 'master':
    bpo-42236: Enhance init and encoding documentation (GH-23109)
    4b9aad4

    @methane
    Copy link
    Member

    methane commented Nov 3, 2020

    I don't think UTF-8 mode should override os.device_encoding() on Windows.

    UTF-8 mode can be used to ignore legacy locale encoding, and os.device_encoding() uses the locale encoding on Unix. So overriding it make sense.

    But locale encoding and console cp are different on Windows. Users may want to know console cp even when they want to use UTF-8 by default for reading/writing text files.

    @vstinner
    Copy link
    Member Author

    vstinner commented Nov 4, 2020

    New changeset 3529718 by Victor Stinner in branch 'master':
    bpo-42236: os.device_encoding() respects UTF-8 Mode (GH-23119)
    3529718

    @vstinner
    Copy link
    Member Author

    vstinner commented Nov 4, 2020

    But locale encoding and console cp are different on Windows. Users may want to know console cp even when they want to use UTF-8 by default for reading/writing text files.

    You're right. My final change leaves Windows unchanged.

    @vstinner vstinner closed this as completed Nov 4, 2020
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants