Skip to content

Remove recommendation in curses module documentation to initialize LC_ALL and encode strings #85263

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

Closed
manueljacob mannequin opened this issue Jun 23, 2020 · 2 comments
Closed
Labels
docs Documentation in the Doc dir

Comments

@manueljacob
Copy link
Mannequin

manueljacob mannequin commented Jun 23, 2020

BPO 41091
Nosy @manueljacob
PRs
  • bpo-41091: Remove recommendation in curses module documentation to initialize LC_ALL and encode strings #21159
  • 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-06-23.15:26:57.516>
    labels = ['docs']
    title = 'Remove recommendation in curses module documentation to initialize LC_ALL and encode strings'
    updated_at = <Date 2020-06-25.22:25:01.188>
    user = 'https://github.com/manueljacob'

    bugs.python.org fields:

    activity = <Date 2020-06-25.22:25:01.188>
    actor = 'mjacob'
    assignee = 'docs@python'
    closed = False
    closed_date = None
    closer = None
    components = ['Documentation']
    creation = <Date 2020-06-23.15:26:57.516>
    creator = 'mjacob'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41091
    keywords = ['patch']
    message_count = 1.0
    messages = ['372178']
    nosy_count = 2.0
    nosy_names = ['docs@python', 'mjacob']
    pr_nums = ['21159']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue41091'
    versions = []

    @manueljacob
    Copy link
    Mannequin Author

    manueljacob mannequin commented Jun 23, 2020

    The documentation for the curses module (https://docs.python.org/3.9/library/curses.html) has the following note:

    Since version 5.4, the ncurses library decides how to interpret non-ASCII data using the nl_langinfo function. That means that you have to call locale.setlocale() in the application and encode Unicode strings using one of the system’s available encodings. This example uses the system’s default encoding:

    import locale
    locale.setlocale(locale.LC_ALL, '')
    code = locale.getpreferredencoding()

    Then use code as the encoding for str.encode() calls.

    The recommendation to call locale.setlocale(locale.LC_ALL, '') is problematic as it initializes all locale categories to the user settings, which might be unintended and is not necessary for curses to work correctly. Initializing LC_CTYPE is sufficient for nl_langinfo() to return the correct encoding. Current versions of Python (*) initialize LC_CTYPE at interpreter startup. Therefore calling locale.setlocale() should not be necessary at all.

    The curses module automatically encodes strings. Therefore the recommendation to manually encode strings is outdated.

    (*) It seems to be the case since 177d921. Why was is not previously done on Python 2 and on Python 3 on Windows?

    @manueljacob manueljacob mannequin assigned docspython Jun 23, 2020
    @manueljacob manueljacob mannequin added the docs Documentation in the Doc dir label Jun 23, 2020
    @manueljacob manueljacob mannequin assigned docspython Jun 23, 2020
    @manueljacob manueljacob mannequin added the docs Documentation in the Doc dir label Jun 23, 2020
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @iritkatriel
    Copy link
    Member

    Duplicate of #91156.

    @iritkatriel iritkatriel moved this to Done in Curses issues Nov 7, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    docs Documentation in the Doc dir
    Projects
    Status: Done
    Development

    No branches or pull requests

    1 participant