Skip to content

Comments

gh-123853: Cleanup Windows 95 locale fallback support#144738

Open
mokurin000 wants to merge 3 commits intopython:mainfrom
mokurin000:chore/cleanup-win95-locale
Open

gh-123853: Cleanup Windows 95 locale fallback support#144738
mokurin000 wants to merge 3 commits intopython:mainfrom
mokurin000:chore/cleanup-win95-locale

Conversation

@mokurin000
Copy link

@mokurin000 mokurin000 commented Feb 12, 2026

This removed the dead code windows_locale dict, as Windows introduced LOCALE_SISO639LANGNAME and LOCALE_SISO3166CTRYNAME since Windows 98.

Changes:

  • Removed dead code windows_locale dict from Lib/locale.py
  • Removed 0x fallback branch for Windows 95 or earlier in Modules/_localemodule.c
  • Applied ruff formatting to Lib/locale.py

@bedevere-app

This comment was marked as resolved.

1 similar comment
@bedevere-app

This comment was marked as resolved.

@mokurin000 mokurin000 force-pushed the chore/cleanup-win95-locale branch from ee5da1b to 49f6613 Compare February 12, 2026 11:10
@bedevere-app

This comment was marked as resolved.

@mokurin000
Copy link
Author

cc. @malemburg @serhiy-storchaka

Hi! Could you take a look on these changes?

@mokurin000 mokurin000 force-pushed the chore/cleanup-win95-locale branch from 1e06126 to 2d24222 Compare February 12, 2026 12:18
@mokurin000 mokurin000 force-pushed the chore/cleanup-win95-locale branch 6 times, most recently from 4f317a3 to aa0735b Compare February 17, 2026 18:10
@malemburg
Copy link
Member

Are you sure that _locale._getdefaultlocale() will no longer return a Windows locale code ?

@mokurin000
Copy link
Author

mokurin000 commented Feb 21, 2026

Are you sure that _locale._getdefaultlocale() will no longer return a Windows locale code ?

As far as I know, LOCALE_SISO639LANGNAME and LOCALE_SISO3166CTRYNAME are documented as introduced since Windows ME/98, if that stands correctly, the hex code fallback is never getting used since Python 2.6, which dropped support to Windows 95/98/ME (NT 4).

Looking into git blame, the fallback code was written at 26 years ago 8f017a0, but it never get removed, and surprisingly the dictionary was maintained even after Windows 95 support were entirely removed 0a86694

@mokurin000 mokurin000 force-pushed the chore/cleanup-win95-locale branch from aa0735b to efd0a30 Compare February 21, 2026 14:33
@malemburg
Copy link
Member

I think we should still leave a guard in the code, so that such codes do not leak outside the function. The guard should raise an exception and let the user know that something is wrong.

Also, please have a look on Github whether the windows_locale is in use by Python 3 code. We may have to do a deprecation cycle (though it was already indirectly put through this as part of the now undone deprecation of getdefaultencoding()).

@mokurin000
Copy link
Author

mokurin000 commented Feb 21, 2026

I think we should still leave a guard in the code, so that such codes do not leak outside the function. The guard should raise an exception and let the user know that something is wrong.

With the current mechanism, if any of LOCALE_SISO3166CTRYNAME, LOCALE_SISO639LANGNAME was not avaliable, for code a None is returned, and the legacy code in that case (if ever executed) will return None as code when the hex code not found in windows_locale
I will add that into documentation

Also, please have a look on Github whether the windows_locale is in use by Python 3 code. We may have to do a deprecation cycle (though it was already indirectly put through this as part of the now undone deprecation of getdefaultencoding()).

Okay, I will do so soon as have time

@mokurin000
Copy link
Author

mokurin000 commented Feb 21, 2026

Right, undocumented though, there are many code relying on the windows_locale dictionary, it cannot be simply removed..
By the way, where shall I mark a dictionary as deprecated?

@mokurin000 mokurin000 force-pushed the chore/cleanup-win95-locale branch 3 times, most recently from 1ec8e64 to 54e8f97 Compare February 21, 2026 15:10
@bedevere-app
Copy link

bedevere-app bot commented Feb 21, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@mokurin000
Copy link
Author

Now I believe it does no impact to python users, removed the NEWS entry

@mokurin000 mokurin000 force-pushed the chore/cleanup-win95-locale branch from 54e8f97 to 5b3e6bc Compare February 21, 2026 15:12
@bedevere-app
Copy link

bedevere-app bot commented Feb 21, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@serhiy-storchaka serhiy-storchaka self-requested a review February 21, 2026 16:54
Copy link
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.

Should not _locale._getdefaultlocale() raise an exception if the locale is not found (this should never happen on modern Windows)?

@mokurin000
Copy link
Author

Should not _locale._getdefaultlocale() raise an exception if the locale is not found (this should never happen on modern Windows)?

Okay, I will edit accordingly

@bedevere-app
Copy link

bedevere-app bot commented Feb 21, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

mokurin000 and others added 3 commits February 22, 2026 01:35
detect exception for Windows getdefaultlocale, once any of required
constant was unavaliable, fall back to POSIX behaviour.
@mokurin000 mokurin000 force-pushed the chore/cleanup-win95-locale branch from ce33482 to 6cc728a Compare February 21, 2026 17:35
@@ -0,0 +1,2 @@
Removed Windows 95 compatibility code from :func:`_locale._getdefaultlocale`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Removed Windows 95 compatibility code from :func:`_locale._getdefaultlocale`.
Removed Windows 95 compatibility code from :func:`locale.getdefaultlocale`.

_locale._getdefaultlocale is an implementation detail. The public interface is locale.getdefaultlocale.

@@ -0,0 +1,2 @@
Removed Windows 95 compatibility code from :func:`_locale._getdefaultlocale`.
Instead, if ``LOCALE_SISO639LANGNAME`` or ``LOCALE_SISO3166CTRYNAME`` cannot be retrieved, an :class:`OSError` is raised.
Copy link
Member

Choose a reason for hiding this comment

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

This is an implementation detail. And the exception should never be raised.

@malemburg
Copy link
Member

Just to clarify: If the internal API returns an OSError, the Python API should return None.

With "guard" I meant that we don't allow one of these Windows locale codes to be returned by locale.getdefaultencoding() - the API is supposed to return a string or None as code.

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.

4 participants