From 139d5dcd3255eddb822aa2d876ce3120c34d81c7 Mon Sep 17 00:00:00 2001 From: Ankit Goel Date: Thu, 11 Oct 2018 12:54:38 +0530 Subject: [PATCH] Fix bug in implementation of `timeutils.daterange` Currently, the `finished` function used in case of `stop` being None has a different signature than the one used in case of `stop` being a date. This commit remedies that and adds a test for the same. --- boltons/timeutils.py | 2 +- tests/test_timeutils.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/boltons/timeutils.py b/boltons/timeutils.py index 586f967..37a3a55 100644 --- a/boltons/timeutils.py +++ b/boltons/timeutils.py @@ -348,7 +348,7 @@ def daterange(start, stop, step=1, inclusive=False): ' (year, month, day), not: %r' % step) if stop is None: - finished = lambda t: False + finished = lambda now, stop: False elif start < stop: finished = operator.gt if inclusive else operator.ge else: diff --git a/tests/test_timeutils.py b/tests/test_timeutils.py index ba4d030..3e91ce6 100644 --- a/tests/test_timeutils.py +++ b/tests/test_timeutils.py @@ -47,3 +47,9 @@ def test_daterange_years(): assert years_from_2025[0] == date(2025, 1, 1) assert years_from_2025[-1] == date(2017, 1, 1) + +def test_daterange_infinite(): + today = date.today() + infinite_dates = daterange(today, None) + for i in range(10): + assert next(infinite_dates) == today + timedelta(days=i)