Skip to content

PEP 538: Unexpected locale behaviour on *BSD (including Mac OS X) #74857

Closed

Description

@ncoghlan
BPO 30672
Nosy @ronaldoussoren, @ncoghlan, @ned-deily
PRs
  • WIP bpo-34589: Move locale coercion back to the CLI app #9257
  • Dependencies
  • bpo-30647: CODESET error on AMD64 FreeBSD 10.x Shared 3.x caused by the PEP 538
  • bpo-34589: Py_Initialize() and Py_Main() should not enable C locale coercion
  • 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 2017-06-15.09:23:53.311>
    labels = ['3.7', 'type-bug', 'tests']
    title = 'PEP 538: Unexpected locale behaviour on *BSD (including Mac OS X)'
    updated_at = <Date 2020-06-29.10:36:19.078>
    user = 'https://github.com/ncoghlan'

    bugs.python.org fields:

    activity = <Date 2020-06-29.10:36:19.078>
    actor = 'vstinner'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Tests']
    creation = <Date 2017-06-15.09:23:53.311>
    creator = 'ncoghlan'
    dependencies = ['30647', '34589']
    files = []
    hgrepos = []
    issue_num = 30672
    keywords = ['patch']
    message_count = 13.0
    messages = ['296076', '296239', '296248', '296250', '307784', '314646', '314648', '314652', '326710', '354503', '354994', '354995', '372505']
    nosy_count = 3.0
    nosy_names = ['ronaldoussoren', 'ncoghlan', 'ned.deily']
    pr_nums = ['9257']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue30672'
    versions = ['Python 3.7']

    Linked PRs

    Activity

    1. ncoghlan commented on Jun 15, 2017

      @ncoghlan
      ContributorAuthor

      To get the new PEP-538 tests passing on Mac OS X (see [1,2]), I ended up having to skip the following test scenarios:

          LANG=UTF-8 (behaves like LANG=C, *not* LC_CTYPE=UTF-8)
          LANG=POSIX (behaves like a distinct locale is set, not LANG=C)
          LC_CTYPE=POSIX (behaves like a distinct locale is set, not LANG=C)
          LC_ALL=POSIX (behaves like a distinct locale is set, not LANG=C)

      However, I'm not sure whether that should be diagnosed as a pure testing problem, where we change the test's expectations to match the current behaviour, or a bug in the PEP-538 implementation, where we should be updating it to produce the behaviour that the tests were originally expecting.

      [1] 4563099
      [2] 7926516 )

    2. added
      testsTests in the Lib/test dir
      type-bugAn unexpected behavior, bug, or error
      on Jun 15, 2017
    3. ncoghlan commented on Jun 17, 2017

      @ncoghlan
      ContributorAuthor

      For the case where POSIX is a distinct locale from the default C locale (rather than a simple alias), I'm leaning towards taking PEP-538 literally, and adjusting the affected test cases to assume that locale coercion *won't* happen for that case on Mac OS X.

      I *think* we can check for the alias behaviourally by setting the "POSIX" locale and seeing if it reports itself back to us as "C", but if not, then I'll just add in a sys.platform check, and we can figure out a behavioural check later if the platform check turns out to cause problems.

    4. ncoghlan commented on Jun 18, 2017

      @ncoghlan
      ContributorAuthor

      It seems the "POSIX is not just an alias for the C locale" behaviour is inherited from *BSD, rather than being specific to Mac OS X: http://buildbot.python.org/all/builders/AMD64%20FreeBSD%20CURRENT%20Debug%20custom/builds/12/steps/test/logs/stdio

    5. changed the title [-]PEP 538: Unexpected locale behaviour on Mac OS X[/-] [+]PEP 538: Unexpected locale behaviour on *BSD (including Mac OS X)[/+] on Jun 18, 2017
    6. ncoghlan commented on Jun 18, 2017

      @ncoghlan
      ContributorAuthor

      Flagging bpo-30647 as a dependency, since the problem with breaking nl_langinfo will need to be fixed before these tests can be re-enabled.

    7. self-assigned this
      on Jun 18, 2017
    8. ncoghlan commented on Dec 7, 2017

      @ncoghlan
      ContributorAuthor

      As discussed in https://bugs.python.org/issue32238 and https://mail.python.org/pipermail/python-dev/2017-December/151105.html, I now think the right answer for the POSIX case is to ensure the legacy locale detection logic always treats that the same way as it does the C locale.

      LANG=UTF-8 I'm still not sure about - as I understand it, that's a partial locale that only defines LC_CTYPE, which may be why the libc implementation ignores it if you try to set it as a general category default.
    9. ncoghlan commented on Mar 29, 2018

      @ncoghlan
      ContributorAuthor

      Ned, I'd forgotten about the part of this issue which amounts to "Check for 'POSIX' as a locale coercion trigger in addition to 'C', as not every platform aliases the former to the latter the way glibc does".

      So while I don't think this is really a release blocker (as you have to explicitly request the POSIX locale to encounter the discrepancy, and I think fixing it in 3.7.1 would be OK), I *am* bumping it up to "critical", as I think it would be better to resolve this for 3.7.0b4 rather than letting it linger further.

    10. ned-deily commented on Mar 29, 2018

      @ned-deily
      Member

      Thanks for the headsup, Nick. BTW, some of the discussion in languishing bpo-18378 might be relevant here.

    11. ncoghlan commented on Mar 29, 2018

      @ncoghlan
      ContributorAuthor

      The locale module has its own extra layer of oddities that I don't personally understand - bpo-29571 and bpo-20087 are another couple of issues along those lines.

    12. ncoghlan commented on Sep 30, 2018

      @ncoghlan
      ContributorAuthor

      Putting back to normal, as the difference between the C locale and the POSIX locale is that you never get the latter by default - you have to explicitly request it.

      The underlying fix for this is in the PR for bpo-34589.

    13. vstinner commented on Oct 11, 2019

      @vstinner
      Member

      Since this issue has been created, I deeply reworked the Python Initialization with the PEP-587, and I made many changes related to locales and the UTF-8 Mode (PEP-540). What's the status of this issue?

    14. 6 remaining items

    15. added
      3.13only security fixes
      3.14bugs and security fixes
      3.15bugs and security fixes
      and removed on Sep 21, 2025
    16. devdanzin commented on Sep 21, 2025

      @devdanzin
      Member

      This issue sounds valid and actionable, only requiring access to MacOS or *BSD.

    17. added a commit that references this issue on Sep 22, 2025
    18. vstinner commented on Sep 22, 2025

      @vstinner
      Member

      I wrote #139238 to coerce the POSIX locale to a UTF-8 based locale.

    19. added a commit that references this issue on Sep 23, 2025
    20. vstinner commented on Sep 23, 2025

      @vstinner
      Member

      Python 3.15 now coerces also the POSIX locale.

    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.15bugs and security fixesOS-freebsdOS-macOS-netbsdtestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

      Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions