One function

daterange in mahmoud/boltons

The author described this change as Fix infinite daterange issue when start and stop is same (#302). It counts as a record because the check below fails on the code as it stood at 6505c6b55 and passes on 93185b224, with nothing else changed between the two runs.

Fix saved2022-12-08
Sharing licenceBSD-2-Clause · LICENSE
Change size+1 1

What the code was meant to do, written into the code itself as a docstring

In the spirit of :func:`range` and :func:`xrange`, the `daterange` generator that yields a sequence of :class:`~datetime.date` objects, starting at *start*, incrementing by *step*, until *stop* is reached. When *inclusive* is True, the final date may be *stop*, **if** *step* falls evenly on it. By default, *step* is one day. See details below for many more details. Args: start (datetime.date): The starting date The first value in the sequence. stop (datetime.date): The stopping date. By default not included in return. Can be `None` to yield an infinite sequence. step (int): The value to increment *start* by to reach *stop*. Can be an :class:`int` number of days, a :class:`datetime.timedelta`, or a :class:`tuple` of integers, `(year, month, day)`. Positive and negative *step* values are supported. inclusive (bool): Whether or not the *stop* date can be returned. *stop* is only returned when a *step* falls evenly on it. *Be careful when using stop=None, as this will yield an infinite sequence of dates.*

The change

7171
7272 if stop is None:
7373 finished = lambda now, stop: False
74- elif start < stop:
74+ elif start <= stop:
7575 finished = operator.gt if inclusive else operator.ge
7676 else:
7777 finished = operator.lt if inclusive else operator.le

The check that tells the two apart

failpass·tests/test_timeutils.py::test_daterange_with_same_start_stop

Check file tests/test_timeutils.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it6505c6b5565275d484e0e3907a471944441f0c57
Broken version dated2022-12-08
Moduleboltons.timeutils
Units changeddaterange
Fingerprintc7fdbf48dfd383ff
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in mahmoud/boltons