Skip to content

Check for systemd locale on startup if current locale is set to POSIX #65567

Closed

Description

@ncoghlan
BPO 21368
Nosy @ncoghlan, @vstinner, @merwok, @vadmium

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 2016-12-12.11:51:23.847>
created_at = <Date 2014-04-27.19:30:25.777>
labels = ['interpreter-core', 'type-feature']
title = 'Check for systemd locale on startup if current locale is set to POSIX'
updated_at = <Date 2017-12-18.14:36:59.077>
user = 'https://github.com/ncoghlan'

bugs.python.org fields:

activity = <Date 2017-12-18.14:36:59.077>
actor = 'vstinner'
assignee = 'none'
closed = True
closed_date = <Date 2016-12-12.11:51:23.847>
closer = 'ncoghlan'
components = ['Interpreter Core']
creation = <Date 2014-04-27.19:30:25.777>
creator = 'ncoghlan'
dependencies = []
files = []
hgrepos = []
issue_num = 21368
keywords = []
message_count = 6.0
messages = ['217313', '217328', '217776', '217813', '282985', '308566']
nosy_count = 4.0
nosy_names = ['ncoghlan', 'vstinner', 'eric.araujo', 'martin.panter']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = None
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue21368'
versions = ['Python 3.4', 'Python 3.5']

Activity

  1. ncoghlan commented on Apr 27, 2014

    @ncoghlan
    ContributorAuthor

    bpo-19977 added "surrogateescape" to the fallback settings for the standard streams if Python 3 appears to be running under the POSIX locale (which Python 3 currently reads as setting a default encoding of ASCII, which is almost certainly wrong on any modern Linux system).

    If a modern Linux system is using systemd as the process manager, then there will likely be a "/etc/locale.conf" file providing settings like LANG - due to problematic requirements in the POSIX specification, this file (when available) is likely to be a better "source of truth" regarding the system encoding than the environment where the interpreter process is started, at least when the latter is claiming ASCII as the default encoding.

    See http://www.freedesktop.org/software/systemd/man/locale.conf.html for more details.

  2. vstinner commented on Apr 27, 2014

    @vstinner
    Member

    I don't think that Python should read such configuration file. If you consider that something is wrong here, please report the issue to the C library.

  3. skrah commented on May 2, 2014

    skrahmannequin
    Mannequin

    Why is the default encoding of POSIX wrong on a modern Linux system?
    Today I installed Debian testing, and the first question of the
    installer is to choose between "C" and "English" locales for the
    install. This with the remark that the chosen locale will be
    the default system locale.

  4. ncoghlan commented on May 3, 2014

    @ncoghlan
    ContributorAuthor

    That's the problem - even on UTF-8 systems, Linux programs will often be
    started in a misconfigured environment: the POSIX locale. Python 2 doesn't
    try to interpret the binary data as text, so it doesn't care. Python 3
    *does* care, since it automatically converts several pieces of OS provided
    data to text using the locale encoding.

    systemd tackles that by adding the extra config file to ensure *all* the
    environments it creates get the right config, and to provide a more
    reliable "source of truth" as to the actual likely encoding of system
    interfaces.

    However, a fair bit of groundwork is needed to avoid any innate reliance on
    the locale encoding before we can reliably override it by default, so this
    issue is unlikely to go anywhere before PEP-432 is implemented (and even
    then, actually changing the behaviour would be a separate discussion).

  5. ncoghlan commented on Dec 12, 2016

    @ncoghlan
    ContributorAuthor

    While this is still a problem I'm interested in solving, I no longer think reading the systemd locale config file would be a good way to address it.

    See bpo-28180 for a more recent discussion of some other alternatives.

  6. vstinner commented on Dec 18, 2017

    @vstinner
    Member

    Follow-up: the PEP-538 (bpo-28180) and PEP-540 (bpo-29240) have been accepted and implemented in Python 3.7!

  7. transferred this issue fromon Apr 10, 2022
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

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions