-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Deprecation of locale.getdefaultlocale breaks POSIX compatibility on Windows platform #130796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
EDIT: Actually it seems to only be deprecated and planned for removal in 3.15: #111187. |
I don't think I - or others - was asking for a reinstatement, just a viable alternative for the cases where POSIX locales are expected for use with other tools such as gettext. And yes, removal is planned for 3.15, hence the discussion now. As noted in wesnoth/wesnoth#9972 (comment), it's difficult to know how to work around the removal of |
On my Windows 11 VM, getlocale() returns a "POSIX" locale as expected:
Can you please elaborate your issue? What are the results of |
It's as I described above and in #90817 (comment).
@shineworld reported something similar in #90817 (comment) @Elvish-Hunter reports the same in wesnoth/wesnoth#9972 (comment) |
The reason why POSIX compatibility breaks is this:
Windows 22H2, Python 3.13.1: >>> locale.setlocale(locale.LC_CTYPE)
'English_United States.1252'
>>> locale.getlocale()
('English_United States', '1252')
>>> locale.getdefaultlocale()
('en_US', 'cp1252') |
I would like to know how can I find out the system locale for LC_TIME without using >>> locale.getdefaultlocale(["LC_TIME"])
('ru_RU', 'UTF-8')
>>> locale.setlocale(locale.LC_TIME)
'C'
>>> locale.getlocale(locale.LC_TIME)
(None, None) Apparently I have no other option than to change the interpreter locale: >>> locale.setlocale(locale.LC_TIME, "")
'ru_RU.UTF-8'
>>> locale.getlocale(locale.LC_TIME)
('ru_RU', 'UTF-8') It is generally a bad idea to call setlocale() in some library routine, since as a side effect it affects the entire program. Saving and restoring it is almost as bad: it is expensive and affects other threads that happen to run before the settings have been restored. I see that the original reason for removal is the use of non-ASCII characters in locale. Do you think this is a common case? If fixing the problem is difficult or impossible, perhaps it is worth introducing a similar function called |
Bug report
Bug description:
Follow-up to #90817.
In summary, without
getdetfaultlocale
, tools that rely on POSIX locales cannot reliably get the same information fromgetlocale
orsetlocale
on Windows.For example, Linux will return something like 'en_AU'. But on Windows,
getlocale
will return something like 'English_Australia'.CPython versions tested on:
3.12, 3.13
Operating systems tested on:
Windows, Linux
The text was updated successfully, but these errors were encountered: