-
Notifications
You must be signed in to change notification settings - Fork 460
Closed
Description
Reproducer:
import datetime
import babel
from babel.dates import format_date
date = datetime.date(2016, 2, 7)
try:
print(format_date(date, locale=''))
except (ValueError, babel.UnknownLocaleError):
print('Invalid Babel locale: ...')Output:
PS> python bug.py
Traceback (most recent call last):
File "...\bug.py", line 8, in <module>
print(format_date(date, locale=''))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\Lib\site-packages\babel\dates.py", line 705, in format_date
locale = Locale.parse(locale or LC_TIME)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\Lib\site-packages\babel\core.py", line 350, in parse
raise TypeError(msg)
TypeError: ("Empty locale identifier value: None\n\nIf you didn't explicitly pass an empty value to a Babel function, this could be caused by there being no suitable locale environment variables for the API you tried to use.",)
This is minimised from Sphinx's test suite, where we've newly been seeing failures only on Windows. After much attempted debugging, I noticed Babel had a recent release. With 2.16, the error message is printed, but in 2.17 a TypeError is raised.
I think this is a regression as locale='' is a valid type (str), but an invalid value. The new code uses locale or LC_TIME, which is None on Windows:
Line 705 in b50a1d2
| locale = Locale.parse(locale or LC_TIME) |
A
tomasr8