Skip to content

Babel 2.17 regression: TypeError on Windows for locale='' #1183

@AA-Turner

Description

@AA-Turner

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:

locale = Locale.parse(locale or LC_TIME)

A

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions