Skip to content

Commit cef8b17

Browse files
seanmccullyvstinner
authored andcommitted
bpo-30409: locale.getpreferredencoding doesn't return result (#1672)
1 parent e6a0b59 commit cef8b17

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

Lib/locale.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -617,22 +617,19 @@ def getpreferredencoding(do_setlocale = True):
617617
except Error:
618618
pass
619619
result = nl_langinfo(CODESET)
620-
if not result and sys.platform == 'darwin':
621-
# nl_langinfo can return an empty string
622-
# when the setting has an invalid value.
623-
# Default to UTF-8 in that case because
624-
# UTF-8 is the default charset on OSX and
625-
# returning nothing will crash the
626-
# interpreter.
627-
result = 'UTF-8'
628-
629620
setlocale(LC_CTYPE, oldloc)
630-
return result
631621
else:
632622
result = nl_langinfo(CODESET)
633-
if not result and sys.platform == 'darwin':
634-
# See above for explanation
635-
result = 'UTF-8'
623+
624+
if not result and sys.platform == 'darwin':
625+
# nl_langinfo can return an empty string
626+
# when the setting has an invalid value.
627+
# Default to UTF-8 in that case because
628+
# UTF-8 is the default charset on OSX and
629+
# returning nothing will crash the
630+
# interpreter.
631+
result = 'UTF-8'
632+
return result
636633

637634

638635
### Database

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,7 @@ Arnaud Mazin
904904
Pam McA'Nulty
905905
Matt McClure
906906
Rebecca McCreary
907+
Sean McCully
907908
Kirk McDonald
908909
Chris McDonough
909910
Greg McFarlane

0 commit comments

Comments
 (0)