[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-24 Thread Marc-Andre Lemburg


Marc-Andre Lemburg  added the comment:

Thanks, Victor.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-24 Thread STINNER Victor


STINNER Victor  added the comment:

locale.getdefaultlocale() is now deprecated.

calendar now uses locale.setlocale() instead of locale.getdefaultlocale().

The ANSI code page alias to MBCS now has better tests and better comments.

Thanks Eryk Sun for your very useful feedback!

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-24 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 4fccf910738d1442852cb900747e6dccb8fe03ef by Victor Stinner in 
branch 'main':
bpo-46659: Enhance LocaleTextCalendar for C locale (GH-31214)
https://github.com/python/cpython/commit/4fccf910738d1442852cb900747e6dccb8fe03ef


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-22 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset b899126094731bc49fecb61f2c1b7557d74ca839 by Victor Stinner in 
branch 'main':
bpo-46659: Deprecate locale.getdefaultlocale() (GH-31206)
https://github.com/python/cpython/commit/b899126094731bc49fecb61f2c1b7557d74ca839


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-22 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset ccbe8045faf6e63d36229ea4e1b9298572cda126 by Victor Stinner in 
branch 'main':
bpo-46659: Fix the MBCS codec alias on Windows (GH-31218)
https://github.com/python/cpython/commit/ccbe8045faf6e63d36229ea4e1b9298572cda126


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-08 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +29388
pull_request: https://github.com/python/cpython/pull/31218

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-08 Thread STINNER Victor


STINNER Victor  added the comment:

Eryk: I created GH-31214 which uses the user preferred locale if the current 
LC_TIME locale is "C" or "POSIX".

Moreover, it no longer gets the current locale when the class is created. If 
locale=locale is passed, just use the current LC_TIME (or the user preferred is 
the locale is "C" or "POSIX").

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-08 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +29384
pull_request: https://github.com/python/cpython/pull/31214

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-08 Thread Eryk Sun


Eryk Sun  added the comment:

> Oh. Serhiy asked me to use LC_TIME rather than LC_CTYPE.

Since Locale*Calendar is documented as not being thread safe, __init__() could 
get the real default via setlocale(LC_TIME, "") when locale=None and the 
current LC_TIME is "C". Restore it back to "C" after getting the default. That 
should usually match the behavior from previous versions that called 
getdefaultlocale(). In cases where it differs, it's fixing a bug because the 
default LC_TIME is the correct default.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-08 Thread STINNER Victor


STINNER Victor  added the comment:

> I think calendar.Locale*Calendar should try the LC_CTYPE locale if LC_TIME is 
> "C", i.e. (None, None). Otherwise, it's introducing new default behavior. For 
> example, with LC_ALL set to "ru_RU.utf8": (...)

Oh. Serhiy asked me to use LC_TIME rather than LC_CTYPE.

See also my example in the PR:
https://github.com/python/cpython/pull/31166#issuecomment-1030887394

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-08 Thread STINNER Victor


STINNER Victor  added the comment:

Serhiy: "getdefaultlocale() falls back to LANG and LANGUAGE. It allows also to 
specify a list of looked up environment variables. How could this use case be 
covered with getlocale()?"

What's your use case to use env vars rather than the current LC_CTYPE locale?

My concern is that when setlocale() is called, the current LC_CTYPE locale is 
inconsistent and you can get mojibake and others issues.

See for example:
https://bugs.python.org/issue43552#msg389069

Marc-Andre Lemburg wants to deprecate it:
https://bugs.python.org/issue43552#msg389076

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-08 Thread Eryk Sun

Eryk Sun  added the comment:

> getdefaultlocale() falls back to LANG and LANGUAGE.

_Py_SetLocaleFromEnv(LC_CTYPE) (e.g. setlocale(LC_CTYPE, "")) gets called at 
startup, except for the isolated configuration [1].

I think calendar.Locale*Calendar should try the LC_CTYPE locale if LC_TIME is 
"C", i.e. (None, None). Otherwise, it's introducing new default behavior. For 
example, with LC_ALL set to "ru_RU.utf8":

3.8:

>>> locale.getlocale(locale.LC_TIME)
(None, None)
>>> locale.getlocale(locale.LC_CTYPE)
('ru_RU', 'UTF-8')
>>> cal = calendar.LocaleTextCalendar()
>>> cal.formatweekday(0, 15)
'  Понедельник  '

3.11.0a5+:

>>> locale.getlocale(locale.LC_TIME)
(None, None)
>>> locale.getlocale(locale.LC_CTYPE)
('ru_RU', 'UTF-8')
>>> cal = calendar.LocaleTextCalendar()
>>> cal.formatweekday(0, 15)
' Monday'
>>> locale.setlocale(locale.LC_TIME, '')
'ru_RU.utf8'
>>> cal = calendar.LocaleTextCalendar()
>>> cal.formatweekday(0, 15)
'  Понедельник  '

---

[1] https://docs.python.org/3/c-api/init_config.html?#isolated-configuration

--
nosy: +eryksun

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-08 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

getdefaultlocale() falls back to LANG and LANGUAGE. It allows also to specify a 
list of looked up environment variables. How could this use case be covered 
with getlocale()?

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-07 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +29377
pull_request: https://github.com/python/cpython/pull/31206

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-07 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 7a0486eaa98083e0407ff491872db6d7a0da2635 by Victor Stinner in 
branch 'main':
bpo-46659: calendar uses locale.getlocale() (GH-31166)
https://github.com/python/cpython/commit/7a0486eaa98083e0407ff491872db6d7a0da2635


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-06 Thread STINNER Victor


STINNER Victor  added the comment:

> New changeset 04dd60e50cd3da48fd19cdab4c0e4cc600d6af30 by Victor Stinner in 
> branch 'main':
> bpo-46659: Update the test on the mbcs codec alias (GH-31168)

This change is not correct, I created bpo-46668 to fix it.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-06 Thread STINNER Victor


STINNER Victor  added the comment:

> Please see the discussion on https://bugs.python.org/issue43552: 
> locale.getpreferredencoding() needs to be deprecated as well. Instead we 
> should have a single locale.getencoding() as outlined there... perhaps in a 
> separate ticket ?! Thanks.

Yeah, I read this issue. But these things are too complicated :-) I prefer to 
move step by step.

Once locale.getencoding() (or a similar function) is added, we can update the 
deprecation message.

I hope to be able to deprecate getdefaultlocale() and to add such new function 
in Python 3.11.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-06 Thread Marc-Andre Lemburg


Marc-Andre Lemburg  added the comment:

> For these reasons, I propose to deprecate locale.getdefaultlocale(): 
> setlocale(), getpreferredencoding() and getlocale() should be used instead.

Please see the discussion on https://bugs.python.org/issue43552: 
locale.getpreferredencoding() needs to be deprecated as well. Instead we should 
have a single locale.getencoding() as outlined there... perhaps in a separate 
ticket ?! Thanks.

--
nosy: +lemburg

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-06 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 06b8f1615b09099fae5c5393334b8716a4144d20 by Victor Stinner in 
branch 'main':
bpo-46659: test.support avoids locale.getdefaultlocale() (GH-31167)
https://github.com/python/cpython/commit/06b8f1615b09099fae5c5393334b8716a4144d20


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-06 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 04dd60e50cd3da48fd19cdab4c0e4cc600d6af30 by Victor Stinner in 
branch 'main':
bpo-46659: Update the test on the mbcs codec alias (GH-31168)
https://github.com/python/cpython/commit/04dd60e50cd3da48fd19cdab4c0e4cc600d6af30


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-06 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +29341
pull_request: https://github.com/python/cpython/pull/31168

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-06 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +29340
pull_request: https://github.com/python/cpython/pull/31167

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-06 Thread STINNER Victor


Change by STINNER Victor :


Added file: https://bugs.python.org/file50606/cal_locale.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-06 Thread STINNER Victor


Change by STINNER Victor :


Removed file: https://bugs.python.org/file50605/cal_locale.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-06 Thread STINNER Victor


STINNER Victor  added the comment:

cal_locale.py: Test calendar.LocaleTextCalendar() default locale, manual test 
for GH-31166.

--
Added file: https://bugs.python.org/file50605/cal_locale.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-06 Thread STINNER Victor


Change by STINNER Victor :


--
keywords: +patch
pull_requests: +29339
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/31166

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46659] Deprecate locale.getdefaultlocale() function

2022-02-06 Thread STINNER Victor


New submission from STINNER Victor :

The locale.getdefaultlocale() function only relies on environment variables. At 
Python startup, Python calls setlocale() is set the LC_CTYPE locale to the user 
preferred encoding.

Since Python 3.7, if the LC_CTYPE locale is "C" or "POSIX", PEP 538 sets the 
LC_CTYPE locale to a UTF-8 variant if available, and PEP 540 ignores the locale 
and forces the usage of the UTF-8 encoding. The *effective* encoding used by 
Python is inconsistent with environment variables.

Moreover, if setlocale() is called to set the LC_CTYPE locale to a locale 
different than the user locale, again, environment variables are inconsistent 
with the effective locale.

In these cases, locale.getdefaultlocale() result is not the expected locale and 
it can lead to mojibake and other issues.

For these reasons, I propose to deprecate locale.getdefaultlocale(): 
setlocale(), getpreferredencoding() and getlocale() should be used instead.

For the background on these issues, see recent issue:

* bpo-43552
* bpo-43557

--
components: Library (Lib)
messages: 412647
nosy: vstinner
priority: normal
severity: normal
status: open
title: Deprecate locale.getdefaultlocale() function
versions: Python 3.11

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com