https://github.com/python/cpython/commit/2d3dec0fbda9460cfc3d2ee786969f7d0c7530ea
commit: 2d3dec0fbda9460cfc3d2ee786969f7d0c7530ea
branch: main
author: Guo Ci <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-05-11T17:21:03+03:00
summary:
gh-140924: In locale module, add missing names to __all__ (GH-140925)
files:
A Misc/NEWS.d/next/Library/2025-11-02-22-24-13.gh-issue-140924.NQVbR_.rst
M Lib/locale.py
M Lib/test/test_locale.py
diff --git a/Lib/locale.py b/Lib/locale.py
index 4ff6f8c0f0a775..25efff5b856854 100644
--- a/Lib/locale.py
+++ b/Lib/locale.py
@@ -17,17 +17,14 @@
from builtins import str as _builtin_str
import functools
-# Try importing the _locale module.
-#
-# If this fails, fall back on a basic 'C' locale emulation.
-
# 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.
__all__ = ["getlocale", "getdefaultlocale", "getpreferredencoding", "Error",
"setlocale", "localeconv", "strcoll", "strxfrm",
"str", "atof", "atoi", "format_string", "currency",
"normalize", "LC_CTYPE", "LC_COLLATE", "LC_TIME", "LC_MONETARY",
- "LC_NUMERIC", "LC_ALL", "CHAR_MAX", "getencoding"]
+ "LC_NUMERIC", "LC_ALL", "CHAR_MAX", "getencoding", "delocalize",
+ "localize"]
def _strcoll(a,b):
""" strcoll(string,string) -> int.
@@ -41,6 +38,9 @@ def _strxfrm(s):
"""
return s
+# Try importing the _locale module.
+#
+# If this fails, fall back on a basic 'C' locale emulation.
try:
from _locale import *
@@ -91,6 +91,29 @@ def setlocale(category, value=None):
raise Error('_locale emulation only supports "C" locale')
return 'C'
+else:
+ _conditional_constants_names = ["ABDAY_1", "ABDAY_2", "ABDAY_3",
+ "ABDAY_4", "ABDAY_5", "ABDAY_6",
+ "ABDAY_7", "ABMON_1", "ABMON_10",
+ "ABMON_11", "ABMON_12", "ABMON_2",
+ "ABMON_3", "ABMON_4", "ABMON_5",
+ "ABMON_6", "ABMON_7", "ABMON_8",
+ "ABMON_9", "ALT_DIGITS", "CODESET",
+ "CRNCYSTR", "DAY_1", "DAY_2", "DAY_3",
+ "DAY_4", "DAY_5", "DAY_6",
+ "DAY_7", "D_FMT", "D_T_FMT",
+ "ERA", "ERA_D_FMT", "ERA_D_T_FMT",
+ "ERA_T_FMT", "MON_1", "MON_10",
+ "MON_11", "MON_12", "MON_2", "MON_3",
+ "MON_4", "MON_5", "MON_6", "MON_7",
+ "MON_8", "MON_9", "NOEXPR",
+ "RADIXCHAR", "THOUSEP", "T_FMT",
+ "T_FMT_AMPM", "YESEXPR", "AM_STR",
+ "PM_STR"]
+ # The constants defined in _locale are platform-dependent,
+ # so we only include those that are available on the current platform.
+ __all__.extend(vars().keys() & _conditional_constants_names)
+
# These may or may not exist in _locale, so be sure to set them.
if 'strxfrm' not in globals():
strxfrm = _strxfrm
diff --git a/Lib/test/test_locale.py b/Lib/test/test_locale.py
index a06c600cf56689..8057c35f540841 100644
--- a/Lib/test/test_locale.py
+++ b/Lib/test/test_locale.py
@@ -9,6 +9,15 @@
import sys
import codecs
+
+class MiscTestCase(unittest.TestCase):
+ maxDiff = None
+ def test__all__(self):
+ extra = ["localeconv", "strcoll", "strxfrm", "getencoding",
+ "Error"]
+ not_exported = ["locale_encoding_alias", "locale_alias",
"windows_locale"]
+ support.check__all__(self, locale, extra=extra,
not_exported=not_exported)
+
class LazyImportTest(unittest.TestCase):
@cpython_only
def test_lazy_import(self):
diff --git
a/Misc/NEWS.d/next/Library/2025-11-02-22-24-13.gh-issue-140924.NQVbR_.rst
b/Misc/NEWS.d/next/Library/2025-11-02-22-24-13.gh-issue-140924.NQVbR_.rst
new file mode 100644
index 00000000000000..91c30c95469f08
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-11-02-22-24-13.gh-issue-140924.NQVbR_.rst
@@ -0,0 +1,3 @@
+Add :func:`locale.localize`, :func:`locale.delocalize`
+and platform-specific locale constants
+from the :mod:`!_locale` module to ``locale.__all__``.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]