Skip to content

gh-140924: In locale module, add missing functions to __all__#140925

Merged
serhiy-storchaka merged 15 commits into
python:mainfrom
guoci:locale__all__fix
May 11, 2026
Merged

gh-140924: In locale module, add missing functions to __all__#140925
serhiy-storchaka merged 15 commits into
python:mainfrom
guoci:locale__all__fix

Conversation

@guoci
Copy link
Copy Markdown
Contributor

@guoci guoci commented Nov 2, 2025

@guoci guoci marked this pull request as ready for review November 2, 2025 22:24
Comment thread Lib/locale.py
Copy link
Copy Markdown
Contributor

@cmaloney cmaloney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good improvement as is, localize and delocalize are both documented functions in the module.

https://docs.python.org/3/library/locale.html#locale.delocalize
https://docs.python.org/3/library/locale.html#locale.localize

@guoci
Copy link
Copy Markdown
Contributor Author

guoci commented Nov 3, 2025

I think you want the test to be in a separate PR, I will revert the "add test" commit.

@cmaloney
Copy link
Copy Markdown
Contributor

cmaloney commented Nov 3, 2025

I hadn't realized how long the list of entries expected to be left out was for this module... I'm planning to propose a more general that that covers every stdlib module which uses __all__ rather than per-module ones so okay to me adding no test here.

@cmaloney
Copy link
Copy Markdown
Contributor

cmaloney commented Nov 4, 2025

cc: @malemburg (Experts index for locale)

@malemburg
Copy link
Copy Markdown
Member

malemburg commented Nov 4, 2025

These API are available in the locale module, but not listed in __all__:

['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', 'AM_STR', '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', 'PM_STR', 'RADIXCHAR', 'THOUSEP', 'T_FMT', 'T_FMT_AMPM', 'YESEXPR', 'bind_textdomain_codeset', 'bindtextdomain', 'dcgettext', 'delocalize', 'dgettext', 'encodings', 'functools', 'gettext', 'locale_alias', 'locale_encoding_alias', 'localize', 'nl_langinfo', 're', 'sys', 'textdomain', 'windows_locale']

(there may be more - I currently only have access to Python 3.12)

Out of these I found these to be undocumented / only used internally:

  • AM_STR - appears to be a documentation bug, this is for nl_langinfo()
  • PM_STR - appears to be a documentation bug, this is for nl_langinfo()
  • encodings - imported package
  • functools - imported package
  • locale_alias - this is a documentation bug, since the table is actually being used outside the module
  • locale_encoding_alias - documentation bug, same as above
  • re- imported module
  • sys - imported module
  • windows_locale - documentation bug, same as above

@malemburg
Copy link
Copy Markdown
Member

malemburg commented Nov 4, 2025

Here's a quick script to check these things:

#!/usr/bin/env python3
import locale
import types

public = {name for name in dir(locale) if not name.startswith('_')}
public_no_modules = public - {
    name
    for name in public if isinstance(getattr(locale, name), types.ModuleType)}
missing = sorted(public_no_modules - set(locale.__all__))
print (f'These attributes are missing from locale.__all__: {missing!r}')

@guoci
Copy link
Copy Markdown
Contributor Author

guoci commented Nov 5, 2025

Does this PR need any more modification?

@malemburg
Copy link
Copy Markdown
Member

Does this PR need any more modification?

It would be good to add the missing attributes to __all__ 🙂 And the test mentioned in the review is missing as well.

Comment thread Lib/test/test_locale.py Outdated
Comment thread Lib/locale.py
Comment thread Misc/NEWS.d/next/Library/2025-11-02-22-24-13.gh-issue-140924.NQVbR_.rst Outdated
Comment thread Lib/locale.py
@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented Nov 9, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@cmaloney
Copy link
Copy Markdown
Contributor

cmaloney commented May 1, 2026

@serhiy-storchaka (made recent changes to locale), @malemburg (reviewed earlier) any chance of getting this in for 3.15?

@cmaloney cmaloney removed the stale Stale PR or inactive for long period of time. label May 1, 2026
Comment thread Lib/locale.py Outdated
Comment thread Misc/NEWS.d/next/Library/2025-11-02-22-24-13.gh-issue-140924.NQVbR_.rst Outdated
@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented May 4, 2026

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@guoci
Copy link
Copy Markdown
Contributor Author

guoci commented May 4, 2026

I have made the requested changes; please review again

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented May 4, 2026

Thanks for making the requested changes!

@malemburg: please review the changes made to this pull request.

@bedevere-app bedevere-app Bot requested a review from malemburg May 4, 2026 21:55
@read-the-docs-community
Copy link
Copy Markdown

read-the-docs-community Bot commented May 4, 2026

@guoci
Copy link
Copy Markdown
Contributor Author

guoci commented May 5, 2026

@malemburg I have fixed the test

@serhiy-storchaka serhiy-storchaka added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label May 11, 2026
Copy link
Copy Markdown
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Copy link
Copy Markdown
Member

@malemburg malemburg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@malemburg
Copy link
Copy Markdown
Member

@serhiy-storchaka You're right in that I listed the tables, but on second thought, I don't believe we should make them more prominent than necessary 🙂

@serhiy-storchaka serhiy-storchaka merged commit 2d3dec0 into python:main May 11, 2026
56 of 58 checks passed
@miss-islington-app
Copy link
Copy Markdown

Thanks @guoci for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@guoci guoci deleted the locale__all__fix branch May 11, 2026 14:22
@serhiy-storchaka
Copy link
Copy Markdown
Member

I think it is safe to backport to 3.15, but what about 3.14 and 3.13? I don't think many people do from locale import *. The main effect of this change is that that names will be shown in the pydoc output.

@bedevere-bot
Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot x86 Debian Installed with X 3.x (no tier) has failed when building commit 2d3dec0.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1244/builds/8272) and take a look at the build logs.
  4. Check if the failure is related to this commit (2d3dec0) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1244/builds/8272

Summary of the results of the build (if available):

Click to see traceback logs
remote: Internal Server Error
fatal: unable to access 'https://github.com/python/cpython.git/': The requested URL returned error: 500

chmod: cannot access 'target/': No such file or directory

make: *** No rule to make target 'distclean'.  Stop.

@malemburg
Copy link
Copy Markdown
Member

I think it is safe to backport to 3.15, but what about 3.14 and 3.13? I don't think many people do from locale import *. The main effect of this change is that that names will be shown in the pydoc output.

I don't think this is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs backport to 3.15 pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants