Fwd: timedelta object recursion bug

Jon Ribbens jon+usenet at unequivocal.eu
Thu Jul 28 11:22:48 EDT 2022


On 2022-07-28, Ben Hirsig <iamgusi at gmail.com> wrote:
> Hi, I noticed this when using the requests library in the response.elapsed
> object (type timedelta). Tested using the standard datetime library alone
> with the example displayed on
> https://docs.python.org/3/library/datetime.html#examples-of-usage-timedelta
>
> It appears as though the timedelta object recursively adds its own
> attributes (min, max, resolution) as further timedelta objects. I’m not
> sure how deep they go, but presumably hitting the recursion limit.
>
>>from datetime import timedelta
>>year = timedelta(days=365)
>>print(year.max)
>   999999999 days, 23:59:59.999999
>>print(year.max.min.max.resolution.max.min)
>   -999999999 days, 0:00:00

Why do you think this is a bug?


More information about the Python-list mailing list