Bug report
Bug description:
Some locales don't have an encoding especifier, and python (wrongly) assumes it is ISO-8859-1, when it may not be. For example, the following code:
import locale
l = locale.getlocale()
print(f"locale: {l}, encoding: {locale.getencoding()}")
locale.setlocale(locale.LC_ALL, l)
Returns:
$ LANG=en_GB.UTF-8 python3 test.py
locale: ('en_GB', 'UTF-8'), encoding: UTF-8
$ LANG=en_IN python3 test.py
locale: ('en_IN', 'ISO8859-1'), encoding: UTF-8
Traceback (most recent call last):
File "/home/emilio/profesional/freexian-ext/test.py", line 5, in <module>
locale.setlocale(locale.LC_ALL, l)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.13/locale.py", line 615, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting
Traceback (most recent call last):
File "/home/emilio/test.py", line 5, in <module>
locale.setlocale(locale.LC_ALL, l)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.13/locale.py", line 615, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting
The en_IN locale uses UTF-8, which is correctly returned in locale.getencoding(), but not in locale.getlocale(). Using the tuple returned by locale.getlocale() in a setlocale call fails.
This probably affects other locales that use UTF-8 as their encoding but don't especify it in the locale name.
This was tested on Debian stable (trixie) with Python 3.13.
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Bug report
Bug description:
Some locales don't have an encoding especifier, and python (wrongly) assumes it is ISO-8859-1, when it may not be. For example, the following code:
Returns:
The
en_INlocale uses UTF-8, which is correctly returned in locale.getencoding(), but not in locale.getlocale(). Using the tuple returned by locale.getlocale() in a setlocale call fails.This probably affects other locales that use UTF-8 as their encoding but don't especify it in the locale name.
This was tested on Debian stable (trixie) with Python 3.13.
CPython versions tested on:
3.13
Operating systems tested on:
Linux