Skip to content

Commit ab71f8b

Browse files
authored
bpo-29571: Fix test_re.test_locale_flag() (GH-12099)
Use locale.getpreferredencoding() rather than locale.getlocale() to get the locale encoding. With some locales, locale.getlocale() returns the wrong encoding. For example, on Fedora 29, locale.getlocale() returns ISO-8859-1 encoding for the "en_IN" locale, whereas locale.getpreferredencoding() reports the correct encoding: UTF-8.
1 parent ef17fdb commit ab71f8b

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Lib/test/test_re.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,8 +1552,7 @@ def test_ascii_and_unicode_flag(self):
15521552
self.assertRaises(re.error, re.compile, r'(?au)\w')
15531553

15541554
def test_locale_flag(self):
1555-
import locale
1556-
_, enc = locale.getlocale(locale.LC_CTYPE)
1555+
enc = locale.getpreferredencoding()
15571556
# Search non-ASCII letter
15581557
for i in range(128, 256):
15591558
try:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix ``test_re.test_locale_flag()``: use ``locale.getpreferredencoding()``
2+
rather than ``locale.getlocale()`` to get the locale encoding. With some
3+
locales, ``locale.getlocale()`` returns the wrong encoding.

0 commit comments

Comments
 (0)