From 4ef6eaf5faf49c7672a43547f81aed5b6cac437d Mon Sep 17 00:00:00 2001 From: Hai Shi Date: Wed, 29 Apr 2020 00:36:38 +0800 Subject: [PATCH 1/6] Remove duplicate import of locale module --- Lib/test/support/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index f48decc704cb8a..d988aaccdcefae 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -1622,7 +1622,6 @@ def run_with_locale(catstr, *locales): def decorator(func): def inner(*args, **kwds): try: - import locale category = getattr(locale, catstr) orig_locale = locale.setlocale(category) except AttributeError: From c84d1f903fa181f94014b58ff157b83d577db495 Mon Sep 17 00:00:00 2001 From: Hai Shi Date: Wed, 29 Apr 2020 01:34:09 +0800 Subject: [PATCH 2/6] retrigger checks From 4a1471eec9240e799e7098679d31f9fbd976121a Mon Sep 17 00:00:00 2001 From: Hai Shi Date: Wed, 29 Apr 2020 12:33:40 +0800 Subject: [PATCH 3/6] remove global import of locale module in test.support --- Lib/test/support/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index d988aaccdcefae..9746ff92e3753e 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -14,7 +14,6 @@ import hashlib import importlib import importlib.util -import locale import os import platform import re @@ -1622,6 +1621,7 @@ def run_with_locale(catstr, *locales): def decorator(func): def inner(*args, **kwds): try: + import locale category = getattr(locale, catstr) orig_locale = locale.setlocale(category) except AttributeError: @@ -2432,6 +2432,7 @@ def skip_if_buggy_ucrt_strfptime(test): See bpo-37552 [Windows] strptime/strftime return invalid results with UCRT version 17763.615 """ + import locale global _buggy_ucrt if _buggy_ucrt is None: if(sys.platform == 'win32' and From 04c0f823e1f39c125fe8f4ac1b4eb90f3b548260 Mon Sep 17 00:00:00 2001 From: Hai Shi Date: Wed, 29 Apr 2020 13:05:07 +0800 Subject: [PATCH 4/6] retrigger checks From 58d39a3ae162c8ac2a1e31d3baf7e6a05c3c838a Mon Sep 17 00:00:00 2001 From: Hai Shi Date: Fri, 1 May 2020 10:58:01 +0800 Subject: [PATCH 5/6] make lazy import locale in gettext --- Lib/gettext.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Lib/gettext.py b/Lib/gettext.py index b98f501884b75a..f0ffb1686fb89d 100644 --- a/Lib/gettext.py +++ b/Lib/gettext.py @@ -46,7 +46,6 @@ # find this format documented anywhere. -import locale import os import re import sys @@ -210,6 +209,7 @@ def func(n): def _expand_lang(loc): + import locale loc = locale.normalize(loc) COMPONENT_CODESET = 1 << 0 COMPONENT_TERRITORY = 1 << 1 @@ -275,6 +275,7 @@ def gettext(self, message): return message def lgettext(self, message): + import locale import warnings warnings.warn('lgettext() is deprecated, use gettext() instead', DeprecationWarning, 2) @@ -296,6 +297,7 @@ def ngettext(self, msgid1, msgid2, n): return msgid2 def lngettext(self, msgid1, msgid2, n): + import locale import warnings warnings.warn('lngettext() is deprecated, use ngettext() instead', DeprecationWarning, 2) @@ -459,6 +461,7 @@ def _parse(self, fp): transidx += 8 def lgettext(self, message): + import locale import warnings warnings.warn('lgettext() is deprecated, use gettext() instead', DeprecationWarning, 2) @@ -473,6 +476,7 @@ def lgettext(self, message): return tmsg.encode(locale.getpreferredencoding()) def lngettext(self, msgid1, msgid2, n): + import locale import warnings warnings.warn('lngettext() is deprecated, use ngettext() instead', DeprecationWarning, 2) @@ -665,6 +669,7 @@ def dgettext(domain, message): return t.gettext(message) def ldgettext(domain, message): + import locale import warnings warnings.warn('ldgettext() is deprecated, use dgettext() instead', DeprecationWarning, 2) @@ -692,6 +697,7 @@ def dngettext(domain, msgid1, msgid2, n): return t.ngettext(msgid1, msgid2, n) def ldngettext(domain, msgid1, msgid2, n): + import locale import warnings warnings.warn('ldngettext() is deprecated, use dngettext() instead', DeprecationWarning, 2) From cef2725b06e5de95da8d7657c3c689250f3d39ff Mon Sep 17 00:00:00 2001 From: Hai Shi Date: Tue, 5 May 2020 00:43:53 +0800 Subject: [PATCH 6/6] Revert "make lazy import locale in gettext" This reverts commit 58d39a3ae162c8ac2a1e31d3baf7e6a05c3c838a. --- Lib/gettext.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Lib/gettext.py b/Lib/gettext.py index f0ffb1686fb89d..b98f501884b75a 100644 --- a/Lib/gettext.py +++ b/Lib/gettext.py @@ -46,6 +46,7 @@ # find this format documented anywhere. +import locale import os import re import sys @@ -209,7 +210,6 @@ def func(n): def _expand_lang(loc): - import locale loc = locale.normalize(loc) COMPONENT_CODESET = 1 << 0 COMPONENT_TERRITORY = 1 << 1 @@ -275,7 +275,6 @@ def gettext(self, message): return message def lgettext(self, message): - import locale import warnings warnings.warn('lgettext() is deprecated, use gettext() instead', DeprecationWarning, 2) @@ -297,7 +296,6 @@ def ngettext(self, msgid1, msgid2, n): return msgid2 def lngettext(self, msgid1, msgid2, n): - import locale import warnings warnings.warn('lngettext() is deprecated, use ngettext() instead', DeprecationWarning, 2) @@ -461,7 +459,6 @@ def _parse(self, fp): transidx += 8 def lgettext(self, message): - import locale import warnings warnings.warn('lgettext() is deprecated, use gettext() instead', DeprecationWarning, 2) @@ -476,7 +473,6 @@ def lgettext(self, message): return tmsg.encode(locale.getpreferredencoding()) def lngettext(self, msgid1, msgid2, n): - import locale import warnings warnings.warn('lngettext() is deprecated, use ngettext() instead', DeprecationWarning, 2) @@ -669,7 +665,6 @@ def dgettext(domain, message): return t.gettext(message) def ldgettext(domain, message): - import locale import warnings warnings.warn('ldgettext() is deprecated, use dgettext() instead', DeprecationWarning, 2) @@ -697,7 +692,6 @@ def dngettext(domain, msgid1, msgid2, n): return t.ngettext(msgid1, msgid2, n) def ldngettext(domain, msgid1, msgid2, n): - import locale import warnings warnings.warn('ldngettext() is deprecated, use dngettext() instead', DeprecationWarning, 2)