Skip to content

gh-151316: Prefer UTF-8 for the en_IN locale alias - #155549

Draft
sankalpsthakur wants to merge 1 commit into
python:mainfrom
sankalpsthakur:fix/151316-locale-encoding
Draft

gh-151316: Prefer UTF-8 for the en_IN locale alias#155549
sankalpsthakur wants to merge 1 commit into
python:mainfrom
sankalpsthakur:fix/151316-locale-encoding

Conversation

@sankalpsthakur

@sankalpsthakur sankalpsthakur commented Aug 11, 2026

Copy link
Copy Markdown

Summary

  • locale.locale_alias['en_in'] incorrectly mapped to en_IN.ISO8859-1 because X11 locale.alias overrides glibc's UTF-8 en_IN during makelocalealias regeneration.
  • On modern glibc systems en_IN is UTF-8-only, so getlocale() invented ISO8859-1 and setlocale(getlocale()) failed.
  • Prefer en_IN.UTF-8 in the alias table and hardcode the same carve-out in Tools/i18n/makelocalealias.py (mirroring c.utf8).

Validation

  • Direct import of in-tree Lib/locale.py (system Python cannot use PYTHONPATH=Lib with this partial checkout due to encodings clash):
    • normalize('en_IN') == 'en_IN.UTF-8'
    • _parse_localename('en_IN') == ('en_IN', 'UTF-8')
    • setlocale(LC_CTYPE, 'en_IN')getlocale()setlocale(..., loc) round-trip succeeded on this host (('en_IN', 'UTF-8'))
  • Full ./configure && make + ./python.exe -m test test_locale was not run here (sparse/partial clone); relying on CI for the built interpreter suite.

Fixes #151316

AI/LLM disclosure

  • AI coding tools (including Grok and/or Codex agent-assisted editing) were used to help draft or modify code and this PR description.
  • I reviewed the complete change, understand the reasoning, and ran the reported local tests before submitting.
  • This submission is original work of authorship under the project CLA / contributor terms; AI output was not pasted unreviewed.

@python-cla-bot

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

CLA not signed

@StanFromIreland

Copy link
Copy Markdown
Member

You'll have to sign the CLA before we can review.

@StanFromIreland
StanFromIreland marked this pull request as draft August 11, 2026 10:28
@sankalpsthakur
sankalpsthakur force-pushed the fix/151316-locale-encoding branch 2 times, most recently from e0bc095 to ffd9b41 Compare August 11, 2026 10:53
X11 locale.alias mapped en_IN to ISO8859-1, so getlocale() invented a
codeset that does not exist on modern UTF-8-only systems and broke
setlocale(getlocale()) round-trips. Prefer en_IN.UTF-8 (mirroring other
modernized aliases) and cover the round-trip in tests.

Signed-off-by: Sankalp Thakur <sankalphimself@gmail.com>
@sankalpsthakur
sankalpsthakur force-pushed the fix/151316-locale-encoding branch from ffd9b41 to b959df9 Compare August 11, 2026 10:53

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it the only locale that could have this issue? I would prefer we sweep them all to check if this is the case first instead of having commits for each locale. Also, I think we should instead have a test class that checks for hardcoded replacements thatwe introduce instead of just the case of en_IN.

Comment thread Lib/test/test_locale.py
self.assertEqual(locale.getlocale(locale.LC_CTYPE), loc)

def test_setlocale_from_getlocale_tuple(self):
# Reproduces the issue report: setlocale(LC_*, getlocale()).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is irrelevant as a comment.

@bedevere-app

bedevere-app Bot commented Aug 11, 2026

Copy link
Copy Markdown

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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

locale.getlocale() returns wrong encoding if the locale name doesn't have one

3 participants