classification
Title: Not obvious that locale.LC_MESSAGES may not exist sometimes (e.g. on Windows)
Type: enhancement Stage:
Components: Documentation Versions: Python 3.11, Python 3.10, Python 3.9, Python 3.8, Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, jack__d, richardmines91
Priority: normal Keywords:

Created on 2021-06-10 23:27 by richardmines91, last changed 2021-06-11 07:21 by richardmines91.

Files
File name Uploaded Description Edit
lc_messages_not_exist.png richardmines91, 2021-06-11 07:21 Proof that locale.LC_MESSAGES may not exist in Python
Messages (4)
msg395588 - (view) Author: Richard Mines (richardmines91) * Date: 2021-06-10 23:27
Documentation page:
https://docs.python.org/3/library/locale.html#locale.LC_MESSAGES

Code comment saying that locale.LC_MESSAGES doesn't exist sometimes:
https://github.com/python/cpython/blob/62f1d2b3d7dda99598d053e10b785c463fdcf591/Lib/locale.py#L25-L26

Code fragment showing that locale.LC_MESSAGES can be non-existent:
https://github.com/python/cpython/blob/62f1d2b3d7dda99598d053e10b785c463fdcf591/Lib/locale.py#L1747-L1752

Reading documentation it's not obvious that locale.LC_MESSAGES may not exist (e.g. Windows - Microsoft Store - Python 3.8)
msg395590 - (view) Author: Jack DeVries (jack__d) * Date: 2021-06-10 23:59
Could it be that _locale throws an ImportError whenever LC_MESSAGES doesn't exist? Then, there are fall-backs defined here:

https://github.com/python/cpython/blob/62f1d2b3d7dda99598d053e10b785c463fdcf591/Lib/locale.py#L45-L85
msg395591 - (view) Author: Jack DeVries (jack__d) * Date: 2021-06-11 00:04
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 */
msg395607 - (view) Author: Richard Mines (richardmines91) * Date: 2021-06-11 07:21
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:
https://github.com/python/cpython/blob/62f1d2b3d7dda99598d053e10b785c463fdcf591/Lib/locale.py#L57

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
History
Date User Action Args
2021-06-11 07:21:26richardmines91setfiles: + lc_messages_not_exist.png

messages: + msg395607
2021-06-11 00:04:49jack__dsetmessages: + msg395591
2021-06-10 23:59:51jack__dsetnosy: + jack__d
messages: + msg395590
2021-06-10 23:27:24richardmines91create