diff --git a/babel/lists.py b/babel/lists.py index b6c859800..8b6952aa0 100644 --- a/babel/lists.py +++ b/babel/lists.py @@ -41,8 +41,10 @@ def format_list( style: Literal[ 'standard', 'standard-short', + 'standard-narrow', 'or', 'or-short', + 'or-narrow', 'unit', 'unit-short', 'unit-narrow', @@ -64,7 +66,7 @@ def format_list( set forth in the CLDR root XML file, and raise a ValueError if no suitable replacement can be found. - The following text is verbatim from the Unicode TR35-49 spec [1]. + Styles follow the Unicode TR35-49 specification [1]. * standard: A typical 'and' list for arbitrary placeholders. @@ -72,12 +74,16 @@ def format_list( * standard-short: A short version of an 'and' list, suitable for use with short or abbreviated placeholder values. eg. "Jan., Feb., and Mar." + * standard-narrow: + A particularly compact list of items joined with the standard style. * or: A typical 'or' list for arbitrary placeholders. eg. "January, February, or March" * or-short: A short version of an 'or' list. eg. "Jan., Feb., or Mar." + * or-narrow: + A particularly compact list of alternatives. * unit: A list suitable for wide units. eg. "3 feet, 7 inches" diff --git a/tests/test_lists.py b/tests/test_lists.py index 448366076..8fe5dfd2d 100644 --- a/tests/test_lists.py +++ b/tests/test_lists.py @@ -22,6 +22,17 @@ def test_format_list(list, locale, expected): assert lists.format_list(list, locale=locale) == expected +@pytest.mark.parametrize( + ('style', 'expected'), + [ + ('standard-narrow', 'apples, pears, plums'), + ('or-narrow', 'apples, pears, or plums'), + ], +) +def test_format_list_narrow_styles(style, expected): + assert lists.format_list(['apples', 'pears', 'plums'], style=style, locale='en') == expected + + def test_format_list_error(): with pytest.raises(ValueError): lists.format_list(['a', 'b', 'c'], style='orange', locale='en')