diff -r 322060740b64 Lib/locale.py --- a/Lib/locale.py Fri Nov 27 01:21:51 2015 -0600 +++ b/Lib/locale.py Fri Nov 27 23:09:55 2015 +0100 @@ -18,6 +18,10 @@ import re import operator import functools +# keep a copy of the builtin str type, because 'str' name is overriden +# in globals by a function +_str = str + try: _unicode = unicode except NameError: @@ -573,7 +577,7 @@ def setlocale(category, locale=None): category may be given as one of the LC_* values. """ - if locale and type(locale) is not type(""): + if locale and not isinstance(locale, (_str, _unicode)): # convert to string locale = normalize(_build_localename(locale)) return _setlocale(category, locale) diff -r 322060740b64 Lib/test/test_locale.py --- a/Lib/test/test_locale.py Fri Nov 27 01:21:51 2015 -0600 +++ b/Lib/test/test_locale.py Fri Nov 27 23:09:55 2015 +0100 @@ -493,6 +493,16 @@ class TestMiscellaneous(unittest.TestCas # longer accept unicode strings. self.assertEqual(locale.normalize(u'en_US'), 'en_US.ISO8859-1') + def test_setlocale_unicode(self): + old_loc = locale.getlocale(locale.LC_ALL) + try: + user_locale = locale.setlocale(locale.LC_ALL, '') + unicode_locale = user_locale.decode('utf-8') + user_locale2 = locale.setlocale(locale.LC_ALL, unicode_locale) + self.assertEqual(user_locale, user_locale2) + finally: + locale.setlocale(locale.LC_ALL, old_loc) + def test_main(): tests = [