Skip to content

Not obvious that locale.LC_MESSAGES may not exist sometimes (e.g. on Windows) #88553

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
richardmines91 mannequin opened this issue Jun 10, 2021 · 5 comments
Closed

Not obvious that locale.LC_MESSAGES may not exist sometimes (e.g. on Windows) #88553

richardmines91 mannequin opened this issue Jun 10, 2021 · 5 comments
Labels
3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@richardmines91
Copy link
Mannequin

richardmines91 mannequin commented Jun 10, 2021

BPO 44387
Nosy @jdevries3133
Files
  • lc_messages_not_exist.png: Proof that locale.LC_MESSAGES may not exist in Python
  • 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 2021-06-10.23:27:24.102>
    labels = ['3.7', '3.8', '3.9', '3.10', '3.11', 'type-feature', 'docs']
    title = 'Not obvious that locale.LC_MESSAGES may not exist sometimes (e.g. on Windows)'
    updated_at = <Date 2021-06-11.07:21:26.140>
    user = 'https://bugs.python.org/richardmines91'

    bugs.python.org fields:

    activity = <Date 2021-06-11.07:21:26.140>
    actor = 'richardmines91'
    assignee = 'docs@python'
    closed = False
    closed_date = None
    closer = None
    components = ['Documentation']
    creation = <Date 2021-06-10.23:27:24.102>
    creator = 'richardmines91'
    dependencies = []
    files = ['50102']
    hgrepos = []
    issue_num = 44387
    keywords = []
    message_count = 4.0
    messages = ['395588', '395590', '395591', '395607']
    nosy_count = 3.0
    nosy_names = ['docs@python', 'jack__d', 'richardmines91']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue44387'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10', 'Python 3.11']

    @richardmines91
    Copy link
    Mannequin Author

    richardmines91 mannequin commented Jun 10, 2021

    Documentation page:
    https://docs.python.org/3/library/locale.html#locale.LC_MESSAGES

    Code comment saying that locale.LC_MESSAGES doesn't exist sometimes:

    cpython/Lib/locale.py

    Lines 25 to 26 in 62f1d2b

    # Yuck: LC_MESSAGES is non-standard: can't tell whether it exists before
    # trying the import. So __all__ is also fiddled at the end of the file.

    Code fragment showing that locale.LC_MESSAGES can be non-existent:

    cpython/Lib/locale.py

    Lines 1747 to 1752 in 62f1d2b

    try:
    LC_MESSAGES
    except NameError:
    pass
    else:
    __all__.append("LC_MESSAGES")

    Reading documentation it's not obvious that locale.LC_MESSAGES may not exist (e.g. Windows - Microsoft Store - Python 3.8)

    @richardmines91 richardmines91 mannequin added 3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes labels Jun 10, 2021
    @richardmines91 richardmines91 mannequin added docs Documentation in the Doc dir type-feature A feature request or enhancement 3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes labels Jun 10, 2021
    @richardmines91 richardmines91 mannequin added docs Documentation in the Doc dir type-feature A feature request or enhancement labels Jun 10, 2021
    @jdevries3133
    Copy link
    Mannequin

    jdevries3133 mannequin commented Jun 10, 2021

    Could it be that _locale throws an ImportError whenever LC_MESSAGES doesn't exist? Then, there are fall-backs defined here:

    cpython/Lib/locale.py

    Lines 45 to 85 in 62f1d2b

    try:
    from _locale import *
    except ImportError:
    # Locale emulation
    CHAR_MAX = 127
    LC_ALL = 6
    LC_COLLATE = 3
    LC_CTYPE = 0
    LC_MESSAGES = 5
    LC_MONETARY = 4
    LC_NUMERIC = 1
    LC_TIME = 2
    Error = ValueError
    def localeconv():
    """ localeconv() -> dict.
    Returns numeric and monetary locale-specific parameters.
    """
    # 'C' locale default values
    return {'grouping': [127],
    'currency_symbol': '',
    'n_sign_posn': 127,
    'p_cs_precedes': 127,
    'n_cs_precedes': 127,
    'mon_grouping': [],
    'n_sep_by_space': 127,
    'decimal_point': '.',
    'negative_sign': '',
    'positive_sign': '',
    'p_sep_by_space': 127,
    'int_curr_symbol': '',
    'p_sign_posn': 127,
    'thousands_sep': '',
    'mon_thousands_sep': '',
    'frac_digits': 127,
    'mon_decimal_point': '',
    'int_frac_digits': 127}

    @jdevries3133
    Copy link
    Mannequin

    jdevries3133 mannequin commented Jun 11, 2021

    Follow-up: nope! My hypothesis was incorrect. This is all that _localemodule.c has to say about LC_MESSAGES:

    #ifdef LC_MESSAGES
        ADD_INT(module, LC_MESSAGES);
    #endif /* LC_MESSAGES */

    @richardmines91
    Copy link
    Mannequin Author

    richardmines91 mannequin commented Jun 11, 2021

    If you need a proof that it is possible that locale.LC_MESSAGES doesn't exist, I've attached a screenshot. Even more I'm showing that locale.LC_TIME may be equal to 5 which is a placeholder for locale.LC_MESSAGES if there is an ImportError:

    LC_MESSAGES = 5

    OS: Windows 10 20H2
    Python: 3.8.10
    Exact link to get python: https://www.microsoft.com/ru-ru/p/python-38/9mssztt1n39l?activetab=pivot:overviewtab

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @cdfarrow
    Copy link

    Duplicate of gh-100766, which was fixed on Jan 5, 2023.
    I'm suggesting formatting the information as a note in this PR

    @hugovk hugovk closed this as not planned Won't fix, can't repro, duplicate, stale Apr 24, 2024
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement
    Projects
    Development

    No branches or pull requests

    2 participants