diff --git a/arrow/arrow.py b/arrow/arrow.py index d6ed7a88..fef66c10 100644 --- a/arrow/arrow.py +++ b/arrow/arrow.py @@ -1263,6 +1263,13 @@ def humanize( return locale.describe(granularity, delta, only_distance=only_distance) else: + + if not granularity: + raise ValueError( + "Empty granularity list provided. " + "Please select one or more from 'second', 'minute', 'hour', 'day', 'week', 'month', 'quarter', 'year'." + ) + timeframes: List[Tuple[TimeFrameLiteral, float]] = [] def gather_timeframes(_delta: float, _frame: TimeFrameLiteral) -> float: diff --git a/tests/test_arrow.py b/tests/test_arrow.py index 589f9114..4c9ca110 100644 --- a/tests/test_arrow.py +++ b/tests/test_arrow.py @@ -2286,6 +2286,13 @@ def test_untranslated_granularity(self, mocker): with pytest.raises(ValueError): arw.humanize(later, granularity="week") + def test_empty_granularity_list(self): + arw = arrow.Arrow(2013, 1, 1, 0, 0, 0) + later = arw.shift(seconds=55000) + + with pytest.raises(ValueError): + arw.humanize(later, granularity=[]) + # Bulgarian is an example of a language that overrides _format_timeframe # Applicabale to all locales. Note: Contributors need to make sure # that if they override describe or describe_mutli, that delta