Skip to content

locale.setlocale() #64992

Closed
Closed

Description

@rene
mannequin
BPO 20793
Nosy @ned-deily
Superseder
  • bpo-3067: setlocale error message is confusing
  • 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 2014-02-27.20:27:36.373>
    created_at = <Date 2014-02-27.11:56:07.274>
    labels = []
    title = 'locale.setlocale()'
    updated_at = <Date 2014-02-28.16:59:01.951>
    user = 'https://bugs.python.org/rene'

    bugs.python.org fields:

    activity = <Date 2014-02-28.16:59:01.951>
    actor = 'rene'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-02-27.20:27:36.373>
    closer = 'ned.deily'
    components = []
    creation = <Date 2014-02-27.11:56:07.274>
    creator = 'rene'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 20793
    keywords = []
    message_count = 3.0
    messages = ['212350', '212382', '212459']
    nosy_count = 2.0
    nosy_names = ['ned.deily', 'rene']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '3067'
    type = None
    url = 'https://bugs.python.org/issue20793'
    versions = ['Python 2.7']

    Activity

    1. rene commented on Feb 27, 2014

      renemannequin
      MannequinAuthor

      locale.setlocale() does not work if you pass it a unicode object instead of a str (locale.py, line 576):

      ``if locale and type(locale) is not type(""):``
      

      Maybe it would be better to do a check like this?

      ``if locale and not isinstance(locale, basestring):``
      

      In particular, this can bite you if you use the unicode_literals future import, displaying a not-so-helpful error message ("ValueError: too many values to unpack" in _build_localename).

    2. ned-deily commented on Feb 27, 2014

      @ned-deily
      Member

      Thanks for the report. There was a lengthy discussion of this behavior a few years ago in bpo-3067. At that time it was decided not to change this behavior for 2.7. I'm not sure if the __future__ "unicode_literals" was considered then, however you can work around it by using the b"" literal syntax:

          locale.setlocale(locale.LC_ALL, b'POSIX')
    3. rene commented on Feb 28, 2014

      renemannequin
      MannequinAuthor

      I see. Thanks for the information.

    4. 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

      No labels
      No labels

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions