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

Improve documentation of locale encoding functions #57283

Open
gjb1002 mannequin opened this issue Sep 30, 2011 · 3 comments
Open

Improve documentation of locale encoding functions #57283

gjb1002 mannequin opened this issue Sep 30, 2011 · 3 comments
Labels
docs Documentation in the Doc dir

Comments

@gjb1002
Copy link
Mannequin

gjb1002 mannequin commented Sep 30, 2011

BPO 13074
Nosy @malemburg, @vstinner, @ezio-melotti, @merwok
Files
  • Issue13074.diff: Add note recommending getpreferredencoding
  • 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 2011-09-30.08:15:33.299>
    labels = ['docs']
    title = 'Improve documentation of locale encoding functions'
    updated_at = <Date 2019-03-15.23:53:33.522>
    user = 'https://bugs.python.org/gjb1002'

    bugs.python.org fields:

    activity = <Date 2019-03-15.23:53:33.522>
    actor = 'BreamoreBoy'
    assignee = 'docs@python'
    closed = False
    closed_date = None
    closer = None
    components = ['Documentation']
    creation = <Date 2011-09-30.08:15:33.299>
    creator = 'gjb1002'
    dependencies = []
    files = ['35782']
    hgrepos = []
    issue_num = 13074
    keywords = ['patch']
    message_count = 3.0
    messages = ['144677', '221582', '221596']
    nosy_count = 6.0
    nosy_names = ['lemburg', 'gjb1002', 'vstinner', 'ezio.melotti', 'eric.araujo', 'docs@python']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'needs patch'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue13074'
    versions = ['Python 3.4', 'Python 3.5']

    @gjb1002
    Copy link
    Mannequin Author

    gjb1002 mannequin commented Sep 30, 2011

    The locale module provides locale.getdefaultlocale and locale.getpreferredencoding. The encodings returned by each are generally subtly different ('ISO8859-1' vs 'ISO-8859-1'), but the difference between these methods is not explained.

    A comment by Martin von Löwis from 2003 in http://bugs.python.org/issue813449 indicates that "getdefaultlocale should not be used in new code", if this is really the case then this should be in the docs.

    Anyone reading the docs from the top will currently encounter getdefaultlocale first and believe that this is the way to get the encoding.

    @gjb1002 gjb1002 mannequin assigned docspython Sep 30, 2011
    @gjb1002 gjb1002 mannequin added the docs Documentation in the Doc dir label Sep 30, 2011
    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jun 25, 2014

    Hopefully the patch speaks for itself.

    @malemburg
    Copy link
    Member

    The two functions serve a different purpose.

    getdefautltlocale() specifically avoids calling setlocale() and is thread-safe on Unix. It's purpose is to return the default locale string, not only the encoding.

    getpreferredencoding() only returns the encoding, but on Unix has to call setlocale() to return correct results and thus is not thread-safe.

    Martin's comment doesn't address this difference and I don't agree with it.

    Regarding the different results, I guess this could be solved by having both function pass the data obtained from the system through _parse_localname() before returning it, but that would have to be a handled in a new issue report.

    @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
    docs Documentation in the Doc dir
    Projects
    Status: No status
    Development

    No branches or pull requests

    1 participant