This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Deprecate gettext.lgettext()
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.8
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: barry, bradengroom, serhiy.storchaka, xtreak
Priority: normal Keywords: patch

Created on 2018-05-31 11:00 by serhiy.storchaka, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 10139 merged serhiy.storchaka, 2018-10-26 18:16
Messages (11)
msg318283 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-05-31 11:00
Using gettext.lgettext() is the one of two right ways of doing translation in Python 2. In Python 2, gettext.gettext() returns a raw 8-bit string as it was written in the translation file. Since different translation files can use different encodings, and the locale encoding can be different from them, gettext.gettext() usually is not appropriate. gettext.lgettext() re-encodes all translated messages from file encodings to the specified one (or to the locale encoding by default). It works properly for str-based messages. Other right way is using gettext.ugettext() which returns a Unicode string.

In Python 3 gettext.gettext() was removed, and gettext.ugettext() was renamed to gettext.gettext(). This is the single right way. gettext.lgettext() still returns messages encoded to bytes, but since virtually all messages are Unicode strings in Python 3, it is virtually useless. At least I don't know any proper use case for it. In addition, gettext.lgettext() was half-broken up to recent times (see issue29755).

Seems gettext.lgettext() was not removed in Python 3.0 just due to an oversight. I suggest to deprecate it in 3.8 and remove it in future versions.
msg318342 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2018-05-31 20:43
+1 - I'm actually surprise it's still there. ;)  Given that the docs have a big red warning to avoid these in Python 3, let's start the process of removal.

Don't forget to also deprecate ldgettext(), lngettext(), and ldngettext()
msg328468 - (view) Author: Braden Groom (bradengroom) * Date: 2018-10-25 19:14
What's the process for deprecating functions? Do we just start by adding a note in the docs?
msg328584 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-26 18:24
It includes three parts:

* Add the code that emits a DeprecationWarning when corresponding functions and arguments are used. It is important to specify the correct stacklevel argument.

* Add tests and/or modify existing test for catching or silencing a DeprecationWarning.

* Document this change: in the module documentation, in the What's New document, and add a news entry.

PR 10139 implements all this.
msg328585 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-26 18:27
Sometime we starts with deprecating just in the documentation, if it is hard to add deprecation in the code or adding it will break a lot of working code. But this is not the case. lgettext() was inherently broken in Python 3.
msg328589 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-10-26 18:38
The deprecation notice is added to the docs and deprecation warnings are raised during usage of the functions. As per the PR some of them are deprecated with 3.8 (master) and will be removed by 3.10. But this depends on the discussion over the deprecation cycle. There were cases in the past where issues were raised in bpo for undeprecation (issue27172) after being deprecated for several versions. There are also cases where the functions that had to be removed were postponed for removal to a later version instead of the one initially shown in warnings.

# Python 3.7 no warnings

$ python3.7
Python 3.7.1rc2 (v3.7.1rc2:6c06ef7dc3, Oct 13 2018, 05:10:29)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from gettext import NullTranslations
>>> NullTranslations().lgettext("test")

# PR branch

(pr_10139) ./python.exe
Python 3.8.0a0 (heads/master:4e3a53bcee, Oct 26 2018, 23:44:23)
[Clang 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from gettext import NullTranslations
>>> NullTranslations().lgettext("test")
<stdin>:1: DeprecationWarning: lgettext() is deprecated, use gettext() instead

Hope it helps
msg328635 - (view) Author: Braden Groom (bradengroom) * Date: 2018-10-27 04:18
Thanks! I'll check out the linked PR. I've seen a few deprecation issues that I couldn't pick up just because I wasn't clear on the deprecation process. Is this documented anywhere in the development guides? I wasn't able to find it if it exists. Is there any interest in adding a section for this?
msg328636 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-27 05:00
New changeset fec35c99aa749bb90cb29349bed6b3393907c4c1 by Serhiy Storchaka in branch 'master':
bpo-33710: Deprecate l*gettext() and related functions in the gettext module. (GH-10139)
msg328639 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-27 05:22
See PEP 4.
msg328644 - (view) Author: Braden Groom (bradengroom) * Date: 2018-10-27 05:45
Ah. Thank you
msg400201 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2021-08-24 10:06
It seems like the docs have a note that these functions were removed in Python 3.10 but they probably missed the release. Doc :
Date User Action Args
2022-04-11 14:59:01adminsetgithub: 77891
2021-08-24 10:06:46xtreaksetmessages: + msg400201
2018-10-27 05:45:25bradengroomsetmessages: + msg328644
2018-10-27 05:22:19serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg328639

stage: patch review -> resolved
2018-10-27 05:00:45serhiy.storchakasetmessages: + msg328636
2018-10-27 04:18:57bradengroomsetmessages: + msg328635
2018-10-26 18:38:50xtreaksetnosy: + xtreak
messages: + msg328589
2018-10-26 18:27:49serhiy.storchakasetmessages: + msg328585
2018-10-26 18:24:06serhiy.storchakasetmessages: + msg328584
2018-10-26 18:16:23serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request9468
2018-10-26 12:47:49serhiy.storchakasetassignee: serhiy.storchaka
2018-10-25 19:14:24bradengroomsetmessages: + msg328468
2018-10-25 19:12:52bradengroomsetnosy: + bradengroom
2018-05-31 20:43:43barrysetmessages: + msg318342
2018-05-31 11:00:56serhiy.storchakacreate